Syntax error: EOF in backquote substitution

I scheduled following cron job:

root@alexus:~# crontab -l | grep ^\@hourly
@hourly OUT=`/usr/lib/nagios/plugins/check_disk --include-type=ext4 --warning=10% --critical=5%` ; if [ $? != 0 ] ; then echo $OUT ; fi
root@alexus:~# OUT=`/usr/lib/nagios/plugins/check_disk --include-type=ext4 --warning=10% --critical=5%` ; if [ $? != 0 ] ; then echo $OUT ; fi
root@alexus:~# cat /etc/issue.net
Ubuntu 14.04.3 LTS
root@alexus:~# 

and even though I'm able to run EXACTLY same one liner within shell, whenever job gets executed via cron, I get following email:

Subject: Cron OUT=`/usr/lib/nagios/plugins/check_disk --include-type=ext4 --warning=10 /bin/sh: 1: Syntax error: EOF in backquote substitution

per subject line, it seems like everything after % sign is missing.

How do I properly escape it without breaking my script?

1

1 Answer

You'll need to check your crontab(5) man page. Some implementations of cron will use % as a newline in the command field, so you can pass data to the command on stdin

* * * * * >$HOME/cron.cat.out cat%hello%world

Then "cron.cat.out" contains 2 lines:

hello
world

You'll need

  • to escape your percent signs
  • I recommend using $() instead of backticks
  • Quote the "$OUT" -- always quote your variables unless you need the specific side-effects of leaving them unquoted.
@hourly OUT=$(/usr/lib/nagios/plugins/check_disk --include-type=ext4 --warning=10\% --critical=5\%) || echo "$OUT"
# ...................................................................................^..............^

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like