1

I have a bash script:start_jenkins.sh which starts a java process.

the command in the script start_jenkins.sh is

#!/bin/bash
echo "starting Jenkins service...... "

nohup java -jar /local/home/mona/jenkins/jenkins.war --httpPort=2261  > nohup_jenkins.out 2>&1 &

echo "Jenkins started .................."

my cronjob setup is

    11 18 * * 2 nohup sh /local/home/mona/jenkins/start_jenkins.sh > /local/home/mona/jenkins/logs/jenkins_`date +\%Y\%m\%d\%H\%M\%S`.log 2>&1

When i am running it manually i am getting log entry in the file : jenkins.out & i can see java process is running.

but when i have scheduled it through cron job its not running. i am not getting any entry in the file jenkins.out while log are entered for echo commands

m0na
  • 11
  • 4
  • `cron` usually has minimal `PATH` set. Try explicitly setting the required `PATH` at the start of your script. – anishsane Oct 15 '19 at 18:38
  • @anishsane I am newbie for cron setup. Could you explain how do I set PATH in cron? – m0na Oct 15 '19 at 18:42
  • 1
    If you are able to run that script successfully from the terminal, check the value of PATH variable (`echo "$PATH"`) (Sample output: `/usr/bin:/bin:/usr/local/bin`). Then whatever value you see, add this line at the start of your shell script: `export PATH=''` (e.g. `export PATH='/usr/bin:/bin:/usr/local/bin'`). – anishsane Oct 15 '19 at 18:48
  • Thanks @anishsane. It worked :) – m0na Oct 15 '19 at 18:55
  • 1
    Glad you got your problem solved, but in the future, be sure to search first as your Q likely has an A. Just searching for `[bash] crontab script not working` returned 130 answers. Good luck. – shellter Oct 15 '19 at 23:09
  • https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it – kvantour Oct 16 '19 at 10:35

0 Answers0