Я пытаюсь сделать различия в двух файлах и сравнить их содержимое, и если они отличаются, отправьте электронное письмо. Ниже мой сценарий, который я не могу заставить работать по какой-то причине. Любые предложения приветствуются.
#!/bin/bash
# This script alert.sh runs every hour in cron
# Created march 15, 2018 Author Dave Taylor
# Variables
frm="Datafile-Monitor@mycompany.com"
# For testing email and script
recipients="dave@mycompany.com"
# 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