Avatar of tektools
tektools asked on

cron.daily not running script

I have the following shell script called mydatabasedump in my cron.daily


source /etc/profile
source ~/.bashrc

/usr/bin/mysqldump --single-transaction  -uDBADMIN -pDBPASSWORD -P3306 -hlocalhost mydatabase >> /opt/db_backups/mydatabase.sql

mv /opt/db_backups/mydatabase.sql /opt/db_backups/mydatabase_`date +%A`.sql

I have crond turned on
[root@ttlicense-web cron.daily]# chkconfig --list | grep crond
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off

I have my file in cron.daily
[root@ttlicense-web cron.daily]# ls
0anacron   mydatabasedump makewhatis.cron  prelink  tmpwatch
0logwatch  logrotate      mlocate.cron     rpm

I used the default for crontab
[root@ttlicense-web etc]# cat crontab
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

but my shell script doesnt run, if I do an sh mydatabasedump in the cron.daily folder I am able to get the database dump. I am not sure what I am missing.
Shell Scripting

Avatar of undefined
Last Comment
Hanno P.S.

8/22/2022 - Mon
Hanno P.S.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks justunix for the response, I have changed my script to the above and changed my cron.daily to run after I changed the script but still nothing.  I am still new to linux scripting so I apologize for my igorance, but what do you mean by contain vaild bourne shell commands?  I can run the file with sh mydatabasedump and ./mydatabasedump the permissions are

-rwxr-xr-x 1 root root  228 May 22 08:34 mydatabasedump


looks like I forgot to restart crond and then it worked.  thanks JustUnix
Hanno P.S.

With "valid bourne shell commands" I wanted to point out that you
will have to make sure that the contents of the files being "sourced"
do adhere to the syntax of the shell you are using.
For example, you may sue
  export MY_VARIABLE=abc
in bash and ksh, but you must use
in sh (Bourne Shell).
The good news is, that bash and ksh do understand sh code without
any change.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes