What's new

Solved Cron job not running?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

XIII

Very Senior Member
Goal: automatically make a nightly backup of configuration files on my router and Raspberry Pi's, using rsnapshot, to an attached USB drive (and to OneDrive via rclone).

I think I have correctly configured rsnapshot/rclone, because manual runs do what I want.

However, the automation seems to fail...

In /jffs/scripts/services-start:
Code:
cru a BackupDaily "0 1 * * * sh /opt/bin/rsnapshot daily"

Output of cru -l:
Code:
0 1 * * * sh /opt/bin/rsnapshot daily #BackupDaily#

So I expected this script to run this morning at 01:00, but that did not seem to happen (no backup on the USB drive)

What did I do wrong? How to debug?
 
Did you reboot your router, that is, re-run /jffs/services-start ?

If not, you can add a cron job manually (saves a reboot) in a terminal:
Code:
cru a BackupDaily "0 1 * * * sh /opt/bin/rsnapshot daily"

Don't forget to preserve everything over reboots (and wear out your nvram):
Code:
nvram commit

If all above is correct, then take a look in the logs, starting perhaps with /var/log/syslog. If still no joy, then make rsnapshot more talkative by adding -v or -vv (I'm not familiar with rsnapshot), re-run and re-check the logs.
 
Last edited:
I don't know if this is the difference, as I don't use rsnapshot, but if it's a binary rather than a script, there's no need for sh.
 
  • Yes, I manually ran /jffs/services-start (the "cru -l" command would not show the entry otherwise?)
  • I was not aware "nvram commit" is needed for a file that is saved (on the JFFS filesystem). Are you sure? (I have never done that...)
  • Only log line for 01:00 is a Skynet line: Skynet: [#] 48665 IPs (+0) -- 1690 Ranges Banned (+0) || 30146 Inbound -- 500 Outbound Connections Blocked! [save] [1s]
  • rsnapshot is a shell/Perl script (first line: #!/opt/bin/perl -w)
 
nvram commit is not required as it is not relevant for jffs scripts.

I suggest that you pipe the output of your cron command to a log file so you can see any errors that it throws:
Code:
cru a BackupDaily "0 1 * * * sh /opt/bin/rsnapshot daily > /opt/tmp/rsnapshot.log 2>&1"
 
I suggest that you pipe the output of your cron command to a log file so you can see any errors that it throws:

Good suggestion! I forgot that my rsnapshot config already writes to a log file...

Code:
[2021-03-02T20:41:09] /opt/bin/rsnapshot daily: completed successfully
[2021-03-03T10:00:14] /opt/bin/rsnapshot daily: started

So it looks like cron did not even execute it at 2013-03-03T01:00...
 
So does this run OK interactively?
Code:
sh /opt/bin/rsnapshot daily
Make sure rsnapshot is executable (chmod u+x /opt/bin/rsnapshot) and remove the sh from cron since it’s a Perl script.
 
Got it working thanks to the help in this topic!

Without seeing Dave’s post (this morning) I decided to run sh /opt/bin/rsnapshot daily (yesterday) on the command line and got all kinds of errors.

Removing sh, as suggested by several people, solved it (and I now have an automatic backup from 1:01 today). Thanks!
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top