0

im working with sun Solaris 10 which legacy system, I have made a script that handles specific producer and it consists of bash/perl/posix/sqlplus/awk around 1k lines and it works fine in standalone mode it would work as expected, but there was an issue where the script does not work in crontab I have followed a lot of suggestion through StackOverflow/stackunixexchange like:

  1. start with shebang #!/bin/bash
  2. script with full permission 777
  3. right crontab time syntax
  4. service restarted
  5. loaded all environment variables in the top of the shell
  6. set bash at the beginning of the script in crontab bash

my issue only on that script and the rest of scripts works fine maybe because the script has to be in bash and crontab runs by default with sh or crontab load minimal environment variable

finally, I have solved the issue by inserting the needed shell into another shell and run it through the new shell by setting the new shell in crontab, after this step I can see the crontab worked fine and it can run the script but the issue the script does not do the expected job, it skips bash statements like if statements and other jobs like sqlplus producers /Perl statements can you please tell how can solve this issue, this problem happened only when scheduling the script into crontab

shell in crontab looks like :

10 10,16 * * 1,4 bash /rate/u01/WORK/MP/ERROR/USAGE_REJECTIONS/HolderUsageShell.sh

the script starts as below :

#!/bin/bash 
#environment shell contains all environment variables, I have tried to run it with/without and I got the same thing
/rate/environment.sh >/dev/null

cd /rate/path/
CurrentHour=$(date +%I)
DAY_In_Word=$(date +%A)

if [[ "$DAY_In_Word" == "Monday" || "$DAY_In_Word" == "Thursday" ]] && [[ "$CurrentHour" == "10" ]]; then
.
.
.

1 Answers1

0

You cannot change your environment in a subshell: when the subshell ends, changes are lost. The subshell cannot change the parent's environment. You must change the environment in the current shell. Make this change to your script:

/rate/environment.sh >/dev/null

should be

. /rate/environment.sh >/dev/null