0

I've made a tool for backing up website files & DB. It works as expected if ran by any user. Usually it takes around a minute to run in my configuration. When I added it to the cron it starts but exits immediately. If the application experiences any error it loggs in stdout & in the log file, but in this case it logged none. Found following in /var/log/cron

Feb  8 20:43:01 test-server CROND[1522301]: (developer) CMD (/mnt/path/to/bin >> /mnt/path/to/exec.log)
Feb  8 20:43:02 test-server CROND[1522299]: (developer) CMDEND (/mnt/path/to/bin >> /mnt/path/to/exec.log)

The cron

# test cron
47 20 8 * * user /mnt/path/to/bin >> /mnt/path/to/exec.log 

Contents of /mnt/path/to/exec.log

[2024-02-08 20:47:01]  Starting backup

When it runs correctly it looks like following

[2024-02-07 20:13:11]  Starting backup
[2024-02-07 20:13:11] Processing server: 192.168.x.xxx
[2024-02-07 20:13:11] Processing project: 192.168.x.xxx:/path/in/remote/server
[2024-02-07 20:13:11] Processing project: 192.168.x.xxx:/another/path/in/remote/server
[2024-02-07 20:13:25] Processed project: 192.168.x.xxx:/path/in/remote/server
[2024-02-07 20:13:33] Processed project: 192.168.x.xxx:/another/path/in/remote/server
[2024-02-07 20:13:33] Processed server: 192.168.x.xxx
[2024-02-07 20:13:33] ✅ Backup completed

How this can be fixed, so the task gets ran correctly?

  • I voted to close your question as a duplicate because all typical reasons why Cron jobs fail are explained there. Typical is reliance on $PATH entries and often no useful error handling in the batch tool / script – HBruijn Feb 08 '24 at 15:40
  • 1
    The cron successfully starts your program. Your program prints one line and exits for some reason. So you want someone to debug your program and find out why it exists? – AlexD Feb 08 '24 at 15:42
  • Thanks @AlexD I've tested my program in every possible way, It works... but only it does this if run by cron, Same result for root, user & system cron. Do you have any idea about debugging this? – Md. A. Apu Feb 09 '24 at 08:01
  • Questions about debugging are off-topic here. – AlexD Feb 09 '24 at 08:12

0 Answers0