I'm trying to get a cron job to execute every 20 minutes that will check to make sure a directory isn't down and will output a timestamp to a text file if it is. The cron job is
*/20 * * * * if [ -d PATH_TO_FOLDER ] && [ -s "$(ls -A PATH_TO_FOLDER)" ]; then :; else timestamp=$( date +%T ) && destdir=PATH_TO_TEXT_FILE && echo "$timestamp" >> "$destdir"; fi
This will work perfectly when typed in the command window, but whenever I try to run it as a cron job I get the error:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `)'
/bin/sh: -c: line 1: syntax error: unexpected end of file
I can't figure it out. Thanks for the help.
%字符被cron解释为换行符,您需要对其进行转义-请参阅百分号%在crontab中不起作用
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.