파일 내용의 차이점

파일 내용의 차이점

두 파일을 비교하고 내용을 비교하려고 하는데 서로 다른 경우 이메일을 보내드립니다. 아래는 어떤 이유로 출근할 수 없는 스크립트입니다. 어떤 제안이라도 환영합니다.

#!/bin/bash
# This script alert.sh runs every hour in cron
# Created march 15, 2018 Author Dave Taylor

# Variables
frm="[email protected]"

# For testing email and script
recipients="[email protected]"


# This is the Data file checked every Midnight for website results done by curdata.sh script. Results go to the curfile.fil
current=/scripts/results/curfile.fil

# This is the NEW data output file where website is checked every hour done by newdata.sh script. Results go to the datafile.fil
new=/scripts/results/datafile.fil

dpd=`cat /scripts/results/datafile.fil`
dte=`/bin/date`


# check if the contents of the file has changed since midnight.

    if diff $current $new &>/dev/null

        then

# Log it
    echo "$dte" >> /var/log/datapod
    echo "Data file is $dpd" >>  /var/log/datafile

    else
# Create the message

    echo "Current STL Datafile has changed TO:$dpd" > /scripts/results/mesg

# send the email
    mail -s "Alert Data File has changed" -r "$frm" $recipients < /scripts/results/mesg

sleep 3

#Now we update the current data file with the most up to date info.
cat /scripts/results/datafile.fil > /scripts/results/curfile.fil
fi

답변1

이 시도:

#!/bin/bash
frm="[email protected]"
recipients="[email protected]"
current=/scripts/results/curfile.fil
new=/scripts/results/datafile.fil
log=/var/log/datafile
msgfile=/scripts/results/mesg
dte=`/bin/date`
diff $current $new &>/dev/null
if [ $? -eq 0 ];  then
    echo "${dte}: Data file is: $new " >>  $log
else
    echo "Current STL Datafile has changed TO: " > $msgfile
    cat $new >> $msgfile
    mail -s "Alert! Data File has changed" -r "$frm" $recipients < $msgfile
    sleep 3
    cat $new > $current
    echo "${dte}: Data file has changed. Sent mail to $recipients" >>  $log
fi

관련 정보