Question

]# crontab -l

#ROOT CRONTAB test

#22 15 * * * root my_date=`date +\%Y-\%m-\%0e_\%H:\%M:\%S`; /usr/bin/pg_dumpall -U postgres > /home/apache/tactic_backup/postgresDb_${my_date}
53 13 * * * root /home/apache/tactic_custom_tools/backup.sh

]# more /home/apache/tactic_custom_tools/backup.sh

#!/bin/bash                                                               
/usr/bin/pg_dumpall -U postgres > /home/apache/tactic_backup/postgresDb/`date +\%Y-\%m-\%0e_\%H:\%M:\%S

It doesn't create anything under /home/apache/tactic_backup/postgresDb/

But when i run the script or command as root, it works and does the required. But via crontab it doesn't The crontab above is for root. Even in logs it shows that it ran(or so)

Jan 28 13:40:01 bjweb01 crond[13935]: (root) RELOAD (/var/spool/cron/root)
Jan 28 13:40:01 bjweb01 CROND[34555]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jan 28 13:40:01 bjweb01 CROND[34556]: (root) CMD (root /home/apache/tactic_custom_tools/backup.sh)
Jan 28 13:46:47 bjweb01 crontab[34743]: (root) LIST (root)
Jan 28 13:49:53 bjweb01 crontab[34814]: (root) BEGIN EDIT (root)
Jan 28 13:50:01 bjweb01 CROND[34818]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jan 28 13:52:11 bjweb01 crontab[34814]: (root) REPLACE (root)
Jan 28 13:52:11 bjweb01 crontab[34814]: (root) END EDIT (root)
Jan 28 13:53:01 bjweb01 crond[13935]: (root) RELOAD (/var/spool/cron/root)
Jan 28 13:53:01 bjweb01 CROND[34887]: (root) CMD (root /home/apache/tactic_custom_tools/backup.sh)

Any idea what i am missing?

Was it helpful?

Solution

My documentation states that the mentioning of the user (root in this case) after the time restrictions is only valid in the system crontab which is stored at /etc/crontab.

You are showing us users' crontabs (shown with crontab -l) which differ in that aspect; the user must not be given there, even if the user is root.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top