I have scheduled to run the run.sh program like this:
16 09 07 * * root /opt/db_maintain/run.sh > /opt/db_maintain/temp-log
and here is the run.sh:
#/bin/bash #********* Saman ********* TM=$(date --date='40 days ago' '+%F %T') TARGET=/opt/db_maintain/main.sh source $TARGET "$TM"
I have also granted the execute permission to the following files: run.sh main.sh
When I run the program manually, it redirects from run.sh to main.sh with no problems. However, after scheduling it, crontab runs successfully as I checked it with putting some echo statements in run.sh, but I have no idea why run.sh cannot redirect to main.sh, even when I give main.sh execute privileges.
Do you have any idea?
Update: I found out the problem, but I do not know why it behaves like this. In run.sh I was writing #!/bin/bash, but in main.sh, I was writing #!/usr/bin/env bash after I changed #!/bin/bash in run.sh to #!/usr/bin/env bash, it started working. why is this happening? what is the difference between them?