Backup config file every night automatically!

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Please ask that question elsewhere. This topic is strictly for the backup config file stuff. ;)
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Now this is weird. I used the simple form of the command
cp /data/freenas-v1.db /mnt/Ark/Jim/configbak/`date +%Y%m%d`.db
  1. If I paste that command into shell, it executes without a murmur.
  2. When I paste it into the cron task dialog, hit OK, then Run Now, it executes fine.
  3. But when the same cron job runs automatically, I get this error via email and it fails:
Cron <root@Tabernacle> PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" cp /data/freenas-v1.db /mnt/Ark/Jim/configbak/`date +%Y
Syntax error: EOF in backquote substitution
Syntax error: Error in command substitution

Seems like the command is getting truncated when run automatically but not when "Run Now". How can that be?
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Try this:
Code:
"/mnt/Ark/Jim/configbak/`date '+%Y%m%d'`.db"


Instead of this
Code:
/mnt/Ark/Jim/configbak/`date +%Y%m%d`.db
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
@Bidule0hm - with the extra quotes I still get the error when running automatically:

Cron <root@Tabernacle> PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" cp /data/freenas-v1.db "/mnt/Ark/Jim/configbak/`'date +%Y
Syntax error: EOF in backquote substitution
Syntax error: Error in command substitution

And it doesn't even execute with Run Now.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
The single quote is not before date but before +%Y ;)
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Yes I caught that and hoped you wouldn't reply before I tried again :oops: I changed it and ran it automatically and got it again:

Cron <root@Tabernacle> PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" cp /data/freenas-v1.db "/mnt/Ark/Jim/configbak/`date '+%Y
Syntax error: EOF in backquote substitution
Syntax error: Error in command substitution

The whole command is now (copying from cron dialog):
cp /data/freenas-v1.db "/mnt/Ark/Jim/configbak/`date '+%Y%m%d'`.db"
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Isn't that identical to what I used in my previous post?

Edit: duh, missed the slashes. Ok, I'll try that
 
Last edited:

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
No, you don't see the backslashs I added?
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Sorry for the confusion. Now the command in cron is
cp /data/freenas-v1.db "/mnt/Ark/Jim/configbak/`date '+\%Y\%m\%d'`.db"

And got the error again
Cron <root@Tabernacle> PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" cp /data/freenas-v1.db "/mnt/Ark/Jim/configbak/`date '+\
Syntax error: EOF in backquote substitution
Syntax error: Error in command substitution

The bigger question to me is, why won't the original command work for me if it works for cyberjock and others? How could it work when executed immediately but not as a cron task?
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Hmm...

Ok, then I'll say it's a copy-paste problem. Use the original command and try to rewrite with your keyboard every special character (including spaces, shlashs, ...) ;)
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
No joy. If I replace the accents and date code with plain text, it works fine. When I type the accepts and date code back in, it will work if I run it immediately, but not as a scheduled task. My cron seems to be not working right.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Very weird o_O

For now, if you want this to work, you can put your command in a script and execute the script with the cron ;)
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Thanks for this thread Cyberjock. I had set up a cron job that wasn't working so I used your example of backing up the config file to set up my cron job and it works now.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
For now, if you want this to work, you can put your command in a script and execute the script with the cron ;)
Well, at least that works. Thanks.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Sorry, been away from the forums for a few days. Mine still runs as a script. But this does beg the question...

Why can't it work as a command itself?
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
The command alone, in shell or SSH, works fine.
Putting it in the cron dialog and clicking "Run Now" also works.
The only thing that doesn't work is when the cron task runs automatically.

Obviously this is something to do with my own system since others don't seem to have this issue. Now I have the command in a script and the cron job calls the script. That seems to work.
 

Ismael Duarte

Contributor
Joined
Jun 13, 2011
Messages
154
Just something a little different.
I've seen this as is a great idea, I've just started using it but with scp command and authorized keys between 2 servers. Meaning, copying database to another server outside freenas.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
The command alone, in shell or SSH, works fine.
Putting it in the cron dialog and clicking "Run Now" also works.
The only thing that doesn't work is when the cron task runs automatically.

Obviously this is something to do with my own system since others don't seem to have this issue. Now I have the command in a script and the cron job calls the script. That seems to work.

I'm having the same problem when I try to run it as a cron task. I run it as a script and I'm trying to figure out how to make it work as a command. Stay tuned. ;)
 
Top