Results 1 to 5 of 5
Hi,
I have created a bash script to run as non-root user. The script run well when executed from the CLI but not when scheduled as a cron job. Upon ...
- 12-11-2009 #1Just Joined!
- Join Date
- Aug 2009
- Location
- Mumbai, India
- Posts
- 75
[SOLVED] Script run in CLI but not in cron
Hi,
I have created a bash script to run as non-root user. The script run well when executed from the CLI but not when scheduled as a cron job. Upon investigating the cause of this issue I found that I have an variable setup in .bashrc ( EXPORT PYTHONPATH = list of directories). When the script is run as a cron job that variable is supposedly not set. I added that variable to the beginning of the scripts and it works fine when executed as a cron job.
My query is why the variable does not get set for the user when the script is run as a cron job but works fine when executed from a CLI. I vividly remember that prior to server format I never had this variable a part of my script. It was only added to .bashrc of the non root user and would work fine even as a cronjob.
Would appreciate assistance on the same
--Syd
- 12-11-2009 #2
Hi,
I hope that this will clarify things.Linux and me it's a love story
- 12-12-2009 #3Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
- 12-13-2009 #4Just Joined!
- Join Date
- Dec 2009
- Posts
- 8
you can try to source the .bashrc from crontab:
* * * * * . /home/foo/.bashrc; /home/foo/bin/myscript.sh
or if that is not working you can create a wrapper script that sources .bashrc and then calls another script
* * * * * /home/foo/bin/wrapper.sh /home/foo/bin/myscript.sh
- 12-14-2009 #5Just Joined!
- Join Date
- Aug 2009
- Location
- Mumbai, India
- Posts
- 75
RESOLVED - Script run in CLI but not in cron
Hi,
Thanx to all of you'll who have responded. Your replies gave me the reason for the script not working in cron and alternate options of getting the script initialized.
Anyways, as I mentioned earlier, I don't recollect explicitly mentioning those variables in the script before the server was formatted. I'll try to figure that out later.
Thanx.
--Syd



