Issue
Trying to run a VMSTAT every 10 minutes (every 600 seconds 144 times a day) but would like to append the time at the beggining of each line.
0 00 * * * /usr/bin/vmstat 600 144|awk '{now=strftime("%T"); print now $0}' > /home/rory/rory_vmstat`date +\%d`
I keep getting a message in my mail saying:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
This works in the command line: /usr/bin/vmstat 600 144|awk '{now=strftime("%T"); print now $0}' so i'm not sure whats wrong.
I'm sure its nothing too complex, I tried switching the ' and " round but no luck. Any help will be greatly appreciated :)
Solution
You've escaped the last % character here date +\%d
, you likely need to do the same with the first too:
strftime("\%T")
The issue being that cron converts % to a newline and sends the text after the % to stdin of the command, unless that % is escaped.
Answered By - nos