Can anyone help me please. I'm struggling with a issue since hours and can't seem to fix it.
When I execute this script via shell it works and I also get the right email output sent to me, but when it executes via cronjob it somehow always says the backup failed, which isn't correct and it worked manually executing it.
#dokuwiki related
dokudate1=$(date +"%d.%m.%y - %H.%M")
host=$(hostname)
dokudate=$(date +"%m-%d")
dokufunc=$(find|grep "dokuwiki"|grep "$dokudate" > doku.txt)
#tw related
twdate1=$(date +"%d.%m.%y - %H.%M")
host=$(hostname)
twdate=$(date +"%d.%m")
twfunc=$(find|grep "torzon"|grep "$twdate" > tw.txt)
fc1(){
$dokufunc
if
grep -R "dokuwiki" doku.txt > /dev/null
then
echo "..."
echo "dokuwiki backup successfull"
echo -en "dokuwiki backup success!" | mail -s "dokuwiki backup check successfull!" mymail.com
rm doku.txt
else
echo "dokuwiki backup fail"
echo -e "dokuwiki backup fail!" | mail -s "dokuwiki backup check failure!" mymail.com
fi
}
fc2(){
$twfunc
if
grep -R "torzon" tw.txt > /dev/null
then
echo "..."
echo "torzon backup successfull"
echo -en "torzon backup success!" | mail -s "torzon backup check successfull!" mymail.com
rm tw.txt
else
echo "torzon backup fail"
echo -e "torzon backup fail!" | mail -s "torzon backup check failure!" mymail.com
fi
}
fc1
fc2
echo "done"
Thanks!
tw.txtthat your script references, ascronhas a different runtime environment than you do when running scripts manually. You could addset +xto the top of your script, and in thecrontable direct stdout and stderr to/tmp/"${0}".logand/tmp/"${0}".errfor perusal.