LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron JOB won't run - Slackware 12.1 (http://www.linuxquestions.org/questions/linux-newbie-8/cron-job-wont-run-slackware-12-1-a-886445/)

ovidiu84 06-15-2011 04:15 AM

Cron JOB won't run - Slackware 12.1
 
I've checked most of the treads that address this problem on this forum but nothing works for me. With the same configuration the same script runs on debian / ubuntu / centos / redhat servers. But it won't run on Slackware.

Code:

#!/bin/sh

/opt/backup/apache-ant-1.7.1/bin/ant -file /opt/backup/run/full.xml

This is the script ( full path included )

This is the cron config:
Code:

root@ums:/opt/backup/run# cat /var/spool/cron/crontabs/root
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system, but if they don't the average newbie
# might get quite perplexed about getting strange mail every 5 minutes. :^)
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null

55 23 * * * /opt/backup/run/run.sh

I've also tried without the .sh extension, have a "run" script.

The script runs perfect manually. Also there are entries in the cron log

Code:

Jun 12 18:47:01 ums crond[3202]: USER root pid 10241 cmd /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
Jun 12 19:47:01 ums crond[3202]: USER root pid 10243 cmd /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
Jun 12 20:47:01 ums crond[3202]: USER root pid 10245 cmd /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
Jun 12 21:47:01 ums crond[3202]: USER root pid 10247 cmd /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
Jun 12 22:14:01 ums crond[3202]: USER root pid 10249 cmd /opt/backup/run/run.sh

I'm totally baffled by this, I've been doing the backups manually for 3 weeks now, I really need to make this run

I've also tried forwarding the output to a log file .. nothing

catkin 06-15-2011 07:45 AM

Silly question but is the script /opt/backup/run/run.sh?

Have you tried changing the script to something very simple like
Code:

#!/bin/sh
echo running > /tmp/XXX.$$

Have you tried changing the shebang line to #!/bin/bash ?

ovidiu84 06-15-2011 07:55 AM

/var/log/cron entry

Code:

Jun 15 15:39:01 ums crond[3200]: USER root pid 20541 cmd /opt/backup/run/run.sh
Jun 15 15:39:01 ums crond[3200]: USER root pid 20542 cmd /opt/backup/run/temp.sh

crontab
Code:

root@ums:/opt/backup# crontab -l root
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system, but if they don't the average newbie
# might get quite perplexed about getting strange mail every 5 minutes. :^)
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null

39 15 * * * /opt/backup/run/run.sh

39 15 * * * /opt/backup/run/temp.sh

temp.sh
Code:

#!/bin.sh

echo running > /opt/temp.log

file wasn't created ...


I've also tried with #!/bin/bash. Nothing.

EDIT: I've made an error in the temp script (#!/bin.sh instead of #!/bin/bash or #!/bin/sh ). Yes the temp log was created. But my script didn't run.

catkin 06-15-2011 08:06 AM

Quote:

Originally Posted by ovidiu84 (Post 4386334)
Code:

#!/bin.sh

echo running > /opt/temp.log

file wasn't created ...


I've also tried with #!/bin/bash. Nothing.

Typo: #!/bin.sh for #!/bin/sh but if you got #!/bin/bash right that's not the issue. You could try increasing cron of crond (depending on which cron system you have) logging level. Details in cron or crond man page.

ovidiu84 06-15-2011 08:10 AM

Quote:

Originally Posted by catkin (Post 4386349)
Typo: #!/bin.sh for #!/bin/sh but if you got #!/bin/bash right that's not the issue. You could try increasing cron of crond (depending on which cron system you have) logging level. Details in cron or crond man page.

yes, made the correction and made the output but the run.sh script still didn't do anything. any ideas how i can change the logging lvl in cron ? i'm not at all used to slackware, can't find his services or auto run

EDIT: NVM , logging lvl is at 8

Code:

root@ums:/opt/backup/backups# crond --help
dcron 2.3.3
dcron -d [#] -l [#] -S -L logfile -f -b -c dir
-d num  debug level
-l num  log level (8 - default)
-S      log to syslod (defualt)
-L file log to file
-f      run in fordeground
-b      run in background (default)
-c dir  working dir
root@ums:/opt/backup/backups# ps -aux | grep crond
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
root      3200  0.0  0.0  1908  656 ?        S    Jun14  0:00 /usr/sbin/crond -l8
root    20643  0.0  0.0  2060  660 pts/1    S+  15:58  0:00 grep crond


catkin 06-15-2011 08:22 AM

Assuming Slackware 12.1 is like 13.1:
Code:

pkill crond
/usr/sbin/crond -l8 >>/var/log/cron 2>&1

The second command is based on the comment in /etc/rc.d/rc.M

ovidiu84 06-15-2011 08:25 AM

This is the ... I just don't understand, I've found out why, seems I've overlooked a simple thing

the script runs manually from command line without problems and

Code:

root@ums:/opt/backup/backups# echo $JAVA_HOME
/usr/lib/java

But for some reasons, don't know which, the variable doesn't exist for the "enviroment" where cron runs

Code:

root@ums:/opt/backup/backups# ps aux | grep crond
root      3200  0.0  0.0  1908  656 ?        S    Jun14  0:00 /usr/sbin/crond -l8
root    20815  0.0  0.0  2060  660 pts/1    S+  16:13  0:00 grep crond

So cron runs as root, so the tasks should run as root right ? But when the script runs it tells me it can't find JAVA_HOME :/.

I've modified the script and added a
Code:

export JAVA_HOME=/usr/lib/java
It works now. Thanks.

catkin 06-15-2011 08:27 AM

So crond is already running with loglevel 8.

Have you checked root's mail?

You could try a crontab entry like
Code:

* * * * * echo foo > /tmp/cron.foo.log 2>&1

ovidiu84 06-15-2011 08:29 AM

Since the script runs ok manually, and does indeed depend on JAVA_HOME, which I had set. I assumed it should be ok for cron too. But I've never checked, I use the same config on some debian / centos boxes and never had a hitch like this.

catkin 06-15-2011 08:32 AM

Glad you found a solution :)

I don't understand why temp.sh didn't produce /opt/temp.log though; that has nothing to do with Java.

cron sets a limited environmemt. If you want the same environment as when logged on, add -l (letter l) to the shebang line; that makes the shell simulate a logon.

Threads can be marked SOLVED via the Thread Tools menu.

ovidiu84 06-15-2011 08:35 AM

Quote:

Originally Posted by catkin (Post 4386394)
Glad you found a solution :)

I don't understand why temp.sh didn't produce /opt/temp.log though; that has nothing to do with Java.

cron sets a limited environmemt. If you want the same environment as when logged on, add -l (letter l) to the shebang line; that makes the shell simulate a logon.

Threads can be marked SOLVED via the Thread Tools menu.

I had mentioned in my reply that after correcting the #/bin.bash into #!/bin/bash it worked "EDIT: I've made an error in the temp script (#!/bin.sh instead of #!/bin/bash or #!/bin/sh ). Yes the temp log was created. But my script didn't run."

Thanks for the assistance :)


All times are GMT -5. The time now is 11:43 PM.