0

i have a cron in my crontab

45 18 * * * root /bkp_db.sh

but it is not working. it is not being executed. what im doing wrong?

Inside my script:

NOW=$(date +"%Y-%m-%d")
mysqldump -u root apps_db > bkp_apps/dump_app1_$NOW.sql
mysqldump -u root app_db2 > bkp_apps/dump_app2_$NOW.sql
zip -r bkp_apps/bkp_apps_$NOW.zip /var/www/myapps/public_html
2
  • is it executable? i.e. did you run something like chmod +x /bkp_db.sh? is the script actually in the root dir, /? if not, specify the correct path to the script. if it is, move it somewere sane (like /usr/local/sbin) and specify the full updated path to the script. – cas Oct 16 '15 at 1:24
  • yes, it is executable and yes, it is in the root dir / i will try to move to sbin – Quetool Oct 16 '15 at 1:26
4

Your personal crontab file should look like this

45 18 * * * /bkp_db.sh

There are several crontab files, each with a slightly different layout. personal crontab files, edited via crontab -e do not contain the username.

man crontab says,

There    is    one    file    for    each   user's   crontab   under   the
/var/spool/cron/crontabs directory. Users are  not  allowed  to  edit  the
files  under  that directory directly to ensure that only users allowed by
the system to run periodic tasks can add them, and only syntactically cor‐
rect  crontabs  will  be  written  there.   This is enforced by having the
directory writable only by the crontab group and configuring crontab  com‐
mand with the setgid bid set for that specific group.

But if you read man cron you will also read,

Additionally,  in  Debian,  cron reads the files in the /etc/cron.d direc‐
tory.  cron treats the files in /etc/cron.d as in  the  same  way  as  the
/etc/crontab  file (they follow the special format of that file, i.e. they
include the user field). However, they are  independent  of  /etc/crontab:
they  do  not, for example, inherit environment variable settings from it.
This change is specific to Debian  see  the  note  under  DEBIAN  SPECIFIC
below.
3
  • without root? ok, i didn't know that. can you explainme why? – Quetool Oct 16 '15 at 1:38
  • It is already explained. Did you use crontab -e or did you put it in /etc/cron.d/ ? – wurtel Oct 16 '15 at 14:27
  • i use crontab -e – Quetool Oct 16 '15 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.