-2

I define a job with crontab like this

0 2 * * * dbadmin . /home/dbadmin/back.sh

it is not root I want to run this .sh file with dbadmin user.

but when I checked it is not working.

in the log it gives this:

Feb 22 21:16:01 localhost crond[14634]: (*system*) BAD FILE MODE (/etc/crontab)
Feb 22 21:16:01 localhost crond[14634]: (dbadmin) RELOAD (cron/dbadmin)
Feb 22 21:16:01 localhost crond[28451]: (dbadmin) CMD (dbadmin . /home/dbadmin/back.sh)

How can I fix this? thanks in advance

CompEng
  • 7,161
  • 16
  • 68
  • 122

3 Answers3

1

Using the crontab program, you normally have access only to the 5 scheduling fields (minute, hour, day of month, month and day of week). However, with Vixie cron (usually on Linux) by editing the system crontab file (/etc/crontab, as well as files in /etc/cron.d) you can use the 6th field for the username. For example, see How to specify in crontab by what user to run script?

If you use crontab to enter this line

0 2 * * * dbadmin . /home/dbadmin/back.sh
          ^^^^^^^

the "dbadmin" username is treated as the command to execute. You can (as noted in crontab's manual page) use that line in /etc/crontab. I pointed out that this is Vixie (also known as ISC) crontab. Legacy systems such as Solaris have a less capable crontab which would not allow specifying the user to run under.

According to cron's manual page, it will send output via email. Perhaps there was no email because the command "dbadmin" failed.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • thanks for answer , but it does not work, where is the log ? I can not find the logs – CompEng Feb 22 '15 at 16:35
  • Usually cron is setup to send via email whatever was written to the standard error. Looking at the description of Vixie cron (manpage), it does not make that distinction -- but email is where I would look. – Thomas Dickey Feb 22 '15 at 17:46
1

Make a crontab entry as dbadmin without the username in it:

0 2 * * * /home/dbadmin/movefolder.sh > /home/dbadmin/cron.out 2>@1

Each day the logfile /home/dbadmin/cron.out should be replaced by a new one. When you are confident about the cron+movefolder, replace the outputfile with /dev/null.
When above fails, check calling the script as dbadmin:

sh /home/dbadmin/movefolder.sh

When this one works and cron fails, it might be the environment. Try saomething like

0 2 * * * . /home/dbadmin/.profile; /home/dbadmin/movefolder.sh > /home/dbadmin/cron.out 2>@1
Walter A
  • 19,067
  • 2
  • 23
  • 43
  • hi , thanks for answer it gives this log, but it does not do what I expect from it : Feb 22 21:37:01 localhost crond[14634]: (dbadmin) RELOAD (cron/dbadmin) Feb 22 21:37:01 localhost crond[31546]: (dbadmin) CMD (sh /home/dbadmin/back.sh) – CompEng Feb 22 '15 at 19:39
  • You started it from root's cron again. Try small steps, first from commandline and then from local cron. Or replace your script `date` and redirect output again. – Walter A Feb 22 '15 at 19:59
0

You need to use sh command for executing sh file.like following

0 2 * * * dbadmin sh /home/dbadmin/movefolder.sh

Hope it works. Thank you.