I was trying to run a script from a shell, it executed properly. But when I was running this script in
cron, the script does not behave correctly. It runs partially. Then I tried following in cron:
10 10 * * * /data/script1.sh >>/tmp/script1.log 2>&1
After the cron finished executing, I looked up in /tmp/script1.log. It shows:
After some research , I found that cron, by default, runs using /bin/sh shell. Then, I checked my
login shell from /etc/passwd. It was /bin/bash.
So, I added #! /bin/bash at the top of the script. Then, script ran properly when running from cron.
The reason for the script not working properly earlier was that there were some commands inside
the script which does not supported by /bin/sh.