proxmox-stuff icon indicating copy to clipboard operation
proxmox-stuff copied to clipboard

Script not working when running from crontab

Open heisenberg2980 opened this issue 2 years ago • 8 comments

I can execute the script manually without any issue but when I added to cron to run everyday it is not generating any backup file and it is sending and error to healthchecks.io but I cannot see any error in syslog or the output of the script, has anyone manage to get the script working from cron?

heisenberg2980 avatar Oct 30 '22 13:10 heisenberg2980

Care to share your cron? First guess would be you’re not using the full path to the script.

peer69 avatar Oct 30 '22 15:10 peer69

This is my cron:

#Daily backup of this server
00 02 * * *          /root/prox_config_backup.sh >> /root/logs/prox_config_backup.log 2>&1

The script actually executes and it seems it is working, but the backup file is not generated and healthchecks.io reports "(failure, exit status 1)", these are the last lines of the log file after the execution from cron:

/root/./.rnd
/root/./.profile
/root/./prox_config_backup.sh
/root/./.forward
/root/./.config/
/root/./.config/procps/
/root/./.local/
/root/./.local/share/
/root/./.local/share/nano/
/root/./comandosUtiles.txt
/root/./.bash_history
Cleaning up
Healthchecks.io notification is enabled

heisenberg2980 avatar Oct 30 '22 16:10 heisenberg2980

If you look at this issue, crontab might not be the way to go: https://github.com/DerDanilo/proxmox-stuff/issues/25

peer69 avatar Oct 30 '22 16:10 peer69

Thanks, I will have a look, but is there any reason why the script wouldn´t work from crontab? I like to have all my scripts automated in crontab instead of using different methods

heisenberg2980 avatar Oct 30 '22 17:10 heisenberg2980

Not sure, tbh. I’d guess it’s about the environment the script is executed in but I put the script in the cron.weekly folder and it has worked for me since then.

peer69 avatar Oct 30 '22 17:10 peer69

Hi, after glancing through this issue, I felt obligated to make mention that there is always the option of appending the backup script as a vzdump hook script. This has the bonus of integrating nicely into the existing backup system used by Proxmox VE and also that you receive a nice, summarized notification report of both jobs in one e-mail.

# /etc/vzdump.conf
# WARNING: Not sure what would happen if you replaced this line with the path 
# to prox_config_backup.sh directly! It may work or it may fail?!
script: /usr/local/bin/pvehost-hook.pl

So, that script path that I direct vzdump to is a slightly modified version of the vzdump-hook-script.pl script that the official documentation makes reference to. I add in an execute call to your prox_config_backup.sh script at the very end of the Perl script, right before the closing bracket leading to the final else branch. I commented the line above and below the existing script code for your reference in placement; do not copy the // lines below.

# /usr/local/bin/pvehost-hook.pl:jeff
//print "\n";

if($phase eq 'backup-end' || $phase eq 'backup-abort') {
  system("/usr/local/bin/prox_config_backup.sh") == 0
||
    die "Execution of /usr/local/bin/prox_config_backup.sh failed.";
}
//} else {
    //die "got unknown phase '$phase'";
//}

Cheers!

See also

  1. man 1 vzdump
  2. /usr/share/doc/pve-manager/examples/vzdump-hook-script.pl

i8degrees avatar May 05 '23 09:05 i8degrees

solution tar --warning='no-file-ignored' -cvPf "$_filename3" --one-file-system /root/. exit code 1 and execution stops. >> tar --warning='no-file-ignored' -cvPf "$_filename3" --one-file-system /root/. | true

ka7713 avatar Dec 17 '23 13:12 ka7713

Is this something that someone wants to integrate? Otherwise we might close the issue.

DerDanilo avatar Apr 08 '24 17:04 DerDanilo