Operating System - HP-UX
1753769 Members
5255 Online
54796 Solutions
New Discussion юеВ

Re: Script running in shell, not in cron

 
Marco Camacho_1
Frequent Advisor

Script running in shell, not in cron

Hi all.
Is there a way to run .profile file to read all the environment variables and execute a script in the same crontab line?
I run my shell fine in a ssh session, when a i run it from a cron , it does not run due to variables not assigned. I would preferto to read the .profile instead off add all the variables in each script. Thanks all!
Mark-ito
4 REPLIES 4
Patrick Wallek
Honored Contributor

Re: Script running in shell, not in cron

While it is not ideal you can do:

. /path/to/.profile ; /path/to/script

in your crontab command.
Peter Nikitka
Honored Contributor

Re: Script running in shell, not in cron

Hi,

additionally to sourcing, you should check the profile for commands like who, stty, ... which require the existence of a valid tty.

...
if [ -t 1 ]
then stty kill ^K ...
fi
...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Marco Camacho_1
Frequent Advisor

Re: Script running in shell, not in cron

Thanks Peter & Patrick, i'll take in count your advices. Regards.
Mark-ito
Fredrik.eriksson
Valued Contributor

Re: Script running in shell, not in cron

Why not just do like this in the top of your script:

#!/bin/sh
. /path/to/.profile

This will include the .profile and all the definitions in it (it's the "." that does it). This way if you change your .profile all your scripts will also recieve the changes :)
Just remember the space between "." and "/path". "./path" is not the same as ". /path".

Best regards
Fredrik Eriksson