[SOLVED] Crontab not working

ricardodfg

New Member
Apr 12, 2024
4
1
3
Hello!

I have problems related to cron in Proxmox VE 8.1

see below file crontab -e
30 12 * * * /backup.sh
00 21 * * * /backup.sh


file backup.sh
-------------------------------------
#!/bin/bash

INICIO=`date +%d/%m/%Y-%H:%M:%S`
LOG=/var/log/rsync/`date +%Y-%m-%d`.txt

echo " " >> $LOG
echo " " >> $LOG
echo "| ------ ------ ------ ------ ------ ------ -----------" >> $LOG
echo " Sincronizacao iniciada em $INICIO" >> $LOG

rsync -avz /mnt/pve/files_drive/ /mnt/pve/backup_drive/ >> $LOG
FINAL=`date +%d/%m/%Y-%H:%M:%S`

echo " Sincronizacao Finalizada em $FINAL" >> $LOG
echo "| ------ ------ ------ ------ ------ ------ -----------" >> $LOG
echo " " >> $LOG
echo " " >> $LOG
----------------------------------------------

I already executed chmod 777 backup.sh and chmod +x backup.sh
file /etc/crontab (It is original, has not been modified)
---------------------------------------
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }
47 6 * * 7 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; }
52 6 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly;
-----------------------------------------

below system log
Apr 11 12:30:01 hyp CRON[4049281]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Apr 11 12:30:01 hyp CRON[4049282]: (root) CMD (/backup.sh)
Apr 11 12:30:01 hyp CRON[4049281]: pam_unix(cron:session): session closed for user root
Apr 11 12:30:01 hyp postfix/pickup[4048163]: D431D140FE7: uid=0 from=<root>
Apr 11 12:30:01 hyp postfix/cleanup[4049286]: D431D140FE7: message-id=<@hyp.local>
Apr 11 12:30:01 hyp postfix/qmgr[894]: D431D140FE7: from=<root@hyp.local>, size=586, nrcpt=1 (queue active)
Apr 11 12:30:01 hyp postfix/local[4049288]: error: open database /etc/aliases.db: No such file or directory
Apr 11 12:30:01 hyp postfix/local[4049288]: warning: hash:/etc/aliases is unavailable. open database /etc/aliases.db: No such file or directory
Apr 11 12:30:01 hyp postfix/local[4049288]: warning: hash:/etc/aliases: lookup of 'root' failed
Apr 11 12:30:01 hyp postfix/local[4049288]: D431D140FE7: to=<root@hyp.local>, orig_to=<root>, relay=local, delay=0.02, delays=0.01/0/0/0.01, dsn=4.3.0, status=deferred (alias database unavailable)

Apr 11 21:00:01 hyp CRON[4140010]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Apr 11 21:00:01 hyp CRON[4140011]: (root) CMD (/backup.sh)
Apr 11 21:00:01 hyp CRON[4140010]: pam_unix(cron:session): session closed for user root
Apr 11 21:00:01 hyp postfix/pickup[4137050]: 0C737140FEB: uid=0 from=<root>
Apr 11 21:00:01 hyp postfix/cleanup[4140015]: 0C737140FEB: message-id=<@hyp.local>
Apr 11 21:00:01 hyp postfix/qmgr[894]: 0C737140FEB: from=<root@hyp.local>, size=586, nrcpt=1 (queue active)
Apr 11 21:00:01 hyp postfix/local[4140017]: error: open database /etc/aliases.db: No such file or directory
Apr 11 21:00:01 hyp postfix/local[4140017]: warning: hash:/etc/aliases is unavailable. open database /etc/aliases.db: No such file or directory
Apr 11 21:00:01 hyp postfix/local[4140017]: warning: hash:/etc/aliases: lookup of 'root' failed
Apr 11 21:00:01 hyp postfix/local[4140017]: 0C737140FEB: to=<root@hyp.local>, orig_to=<root>, relay=local, delay=0.02, delays=0.01/0/0/0.01, dsn=4.3.0, status=deferred (alias database unavailable)
 
Last edited:
Proxmox is also trying to email you about something (probably the error message of your cron-job). Maybe fix the aliases and/or set a working e-mail for root?
 
The Crontab usually doesn't have a decent PATH variable set, so even simple commands such as rsync in your script might not work at all, because the shell doesn't know where to search for the binaries. You can configure the crontab to set a certain PATH variable, or you can replace the commands with absolute paths - like /usr/bin/rsync .

Usually all the returned terminal messages (stdout and stderr) of cronjob scripts are sent to the owner of the Crontab. This could be via mail or - if there is no valid mail service configured - they might be in the form of a mbox (email) file in /var/root/mail, maybe you can find more information about the errors there.
 
Last edited:
did you really put your script in the root of your root filesystem?
What is the output of "ls -al /" ?


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
Return:

root@hyp:/# ls -al /
total 76
drwxr-xr-x 18 root root 4096 Apr 12 08:12 .
drwxr-xr-x 18 root root 4096 Apr 12 08:12 ..
-rwxrwxrwx 1 root root 500 Apr 12 07:28 bachup.sh
lrwxrwxrwx 1 root root 7 Feb 5 13:38 bin -> usr/bin
drwxr-xr-x 5 root root 4096 Mar 17 15:49 boot
-rwxrwxrwx 1 root root 896 Apr 12 07:28 clean_trash.sh
drwxr-xr-x 19 root root 4360 Mar 26 22:48 dev
drwxr-xr-x 91 root root 4096 Apr 12 08:21 etc
drwxr-xr-x 2 root root 4096 Dec 9 18:08 home
lrwxrwxrwx 1 root root 7 Feb 5 13:38 lib -> usr/lib
lrwxrwxrwx 1 root root 9 Feb 5 13:38 lib64 -> usr/lib64
drwx------ 2 root root 16384 Mar 16 12:29 lost+found
drwxr-xr-x 2 root root 4096 Feb 5 13:38 media
drwxrwxrwx 3 root root 4096 Mar 17 22:33 mnt
drwxr-xr-x 2 root root 4096 Feb 5 13:38 opt
dr-xr-xr-x 330 root root 0 Mar 26 22:48 proc
drwx------ 4 root root 4096 Apr 12 07:39 root
drwxr-xr-x 29 root root 1320 Apr 12 12:35 run
lrwxrwxrwx 1 root root 8 Feb 5 13:38 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Feb 5 13:38 srv
dr-xr-xr-x 13 root root 0 Mar 26 22:48 sys
drwxrwxrwt 8 root root 4096 Apr 12 08:18 tmp
drwxr-xr-x 12 root root 4096 Feb 5 13:38 usr
drwxr-xr-x 11 root root 4096 Feb 5 13:38 var
 
-rwxrwxrwx 1 root root 500 Apr 12 07:28 bachup.sh
I guess you did put it in the root.. Not good from standard system management practices.
That said, you misnamed the file. This is in addition to all the good advice regarding PATH and binary locations.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
I guess you did put it in the root.. Not good from standard system management practices.
That said, you misnamed the file. This is in addition to all the good advice regarding PATH and binary locations.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox

So, I left it at the root because I was having problems, and to try to solve it I moved it to the root.
What would you recommend me to do to be able to run this script through crontab?
 
What would you recommend me to do to be able to run this script through crontab?
I'd start with renaming the file from bachup.sh to backup.sh, or updating your crontab to match.
Continue with adding full paths to all binaries, rsync specifically.
Comment out "rsync" line, change crontab to run every minute, and confirm that the script is executed by checking the log file you create.
If log file is created, it means the script executed, uncomment the rsync line and set the time to run in next 5min. Confirm that its running by checking active processes and your log file.
If everything works, change the time to what you want.

good luck


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
I'd start with renaming the file from bachup.sh to backup.sh, or updating your crontab to match.
Continue with adding full paths to all binaries, rsync specifically.
Comment out "rsync" line, change crontab to run every minute, and confirm that the script is executed by checking the log file you create.
If log file is created, it means the script executed, uncomment the rsync line and set the time to run in next 5min. Confirm that its running by checking active processes and your log file.
If everything works, change the time to what you want.

good luck


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox

thanks bbgeek17, I hadn't seen that the file name was wrong! it was just that! It was so stupid of me!
 
  • Like
Reactions: bbgeek17

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!