I wrote a simple backup script which back ups my stuff on a remote server, everything is working great but I'd like to have some sort of report like "backup successful or not".
this is my script
# backup CHECK
date1=`date +"%d.%m.%y - %H.%M"`
host=`hostname`
twdate=`date +"%d.%m"`
performtw=`ls -la|grep "tw"|grep "$twdate" > tmp1.txt`
echo $performtw
if
cat tmp1.txt|grep "tw"
then
echo backup successfull
printf "tw backup success!" | mail -s "tw backup check $date1 repor$
rm tmp1.txt
else
echo backup failure
printf "sitename backup failure!" | mail -s "site backup check $date1 repor$
rm tmp1.txt
fi
exit
But this isn't working really well and I ask you if there's some simpler and more powerful way to do it? Basically it just needs to check if file exists with the name starting xyz and was created at date xyz.
[[ -s file ]]
... Also, quote your variables.$performtw
declaration - the var's value is set to the stdout of a pipeline that redirects to a file. Also you neednt calldate
twice - you can do so only the first time then${split%.*}
the value as needed. But aside fromtest -s
you might like to know most shells supporttest -nt
which compares mod times between two existing files - it fails if either does not exist or if the one on the left side is not newer than the one on the right.