0

I have a shell script to send notifications. The shell script works well manually from CLI but when put in crontab it does not perform its end task.

To be more specific I checked the script line by line by sending the outputs to a cron.log from crontab which gives the output as expected. But still the end task of sending notification which is via a java command is not working in crontab.

I have checked all possible conditions and don't know what is that i am missing, please help.

crontab:

* * * * * bash absolute_path/script.sh > abolutepath/pushNotCron.log

shell script:

#!/bin/bash

if [ condition ]
then
     some code ........
     java -jar $absPath/$jarFileName "argument"
fi

No errors in the script

sungtm
  • 547
  • 3
  • 12
Rashmi Choudhary
  • 53
  • 1
  • 4
  • 10
  • Try forwarding `stderr` to the file like this: * * * * * /bin/bash absolute_path/script.sh &> abolutepath/pushNotCron.log – Damiox Oct 17 '19 at 04:04

1 Answers1

0

The problem is that when you kick off a job by cron, the shell that gets created by default is created with a minimal environment. To see this, try running a cron job that simply displays all the environment variables (including the PATH).

Some common ways to address this are :

1) Have all your cron scripts start by running the .profile

2) to explicitly invoke the desired ".profile", so :

* * * * * bash ./.profile ; absolute_path/script.sh > abolutepath/pushNotCron.log

3) to have a special cron-wrapper script - see https://stackoverflow.com/a/41756145/681444

racraman
  • 4,988
  • 1
  • 16
  • 16