Can't get cron to work!!

Status
Not open for further replies.

windyboi

Explorer
Joined
Jan 7, 2016
Messages
79
Hi, I'm trying to get the following cron job to run, set up through the Freenas GUI:
Code:
scp freenas@192.168.10.1:/cf/conf/config.xml /mnt/my_pool/Data/Backups/pfsense/`date +\%Y\%m\%d\%H\%M\%S`-config-fw.xml

But each night it shows it fails by emailing me:
Code:
Email title: Cron <root@kenny> PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" scp freenas@192.168.10.1:/cf/conf/config.xml /mnt/my_pool/Data/Backups/pfsense/`date +\

Email contents:
/bin/sh: Syntax error: EOF in backquote substitution
/bin/sh: Syntax error: Error in command substitution

Anyone able to spot the problem? It works fine when I execute it from the command line directly

Thank you!
 
Last edited by a moderator:

m0nkey_

MVP
Joined
Oct 27, 2015
Messages
2,739
Try putting your command in a script, then use cron to call the script.

Code:
#!/usr/bin/env sh
scp freenas@192.168.10.1:/cf/conf/config.xml /mnt/my_pool/Data/Backups/pfsense/`date +\%Y\%m\%d\%H\%M\%S`-config-fw.xml
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
Agree with @m0nkey_ , the slashes in the date format is what caused the error, not because it is wrong, and throwing it in a script is the easy way to fix it.
It probably needs an extra set of quotes around it or something silly to keep the system from prematurely interpreting the slashes in the date format.
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
I don't see why the percent signs in the date format are being escaped. Put single quotes around the date format and remove the backslashes.

And remember: always use full paths in cron jobs. Including full paths to commands.
 
Status
Not open for further replies.
Top