Operating System - HP-UX
1838703 Members
3857 Online
110128 Solutions
New Discussion

problem in crontab execution

 
SOLVED
Go to solution
dawood_2
New Member

problem in crontab execution

hi all,

i have a problem in executing crontab.

i need to set value for a variable before executing my command in crontab. i did the following in a seperate file (setenv.sh) to do the same. Content of the file (setenv.sh) is as follows

#!/bin/sh
export SW_PLATFORM=sol

my crontab will execute this file (setenv.sh) first and then exectue my command which use this variable to execute. But when i execute the command, value of SW_PLATFORM is blank. I also tried to print the value in my crontab. It also printed blank.
How do i set the value of this variable so as my command can able to access the same ?

my crontab looks like this

25 17 * * * echo $PATH 1>/dev/pts/52
25 17 * * * /export/home/dawood/setenv.sh 1>/dev/pts/52
25 17 * * * echo $SW_PLATFORM 1>/dev/pts/52
25 17 * * * /opt/softwire/develop/scripts/sw_admin runregression -proj cartridges -file cartridges/release/generic/scripts/sw_night -m -f -s[cartridges]soapSL.deps

Thanks for the help.

Dawood



10 REPLIES 10
Simon Hargrave
Honored Contributor

Re: problem in crontab execution

Those four commands will run completely independantly of each other, and under different environments, therefore this will not work. You can do something like this: -

25 17 * * * ( export SW_PLATFORM=sol ; /opt/softwire/develop/scripts/sw_admin runregression -proj cartridges -file cartridges/release/generic/scripts/sw_night -m -f -s[cartridges]soapSL.deps )

or

25 17 * * * ( . /export/home/dawood/setenv.sh ; /opt/softwire/develop/scripts/sw_admin runregression -proj cartridges -file cartridges/release/generic/scripts/sw_night -m -f -s[cartridges]soapSL.deps )

Either of those should achieve what you require.
Victor BERRIDGE
Honored Contributor

Re: problem in crontab execution

Hi,
Did you execute your setenv.sh using dot?
I would...
. setenv.sh

Now it should work...


All the best
Victor
Victor BERRIDGE
Honored Contributor

Re: problem in crontab execution

Sorry I missed the point, I didnt realised you set off independant jobs => shells

I doubt you finding an easy solution...

Good luck
Victor
Geoff Wild
Honored Contributor
Solution

Re: problem in crontab execution

You need to take all of this:

echo $PATH 1>/dev/pts/52
/export/home/dawood/setenv.sh 1>/dev/pts/52
echo $SW_PLATFORM 1>/dev/pts/52
/opt/softwire/develop/scripts/sw_admin runregression -proj cartridges -file cartridges/release/generic/scripts/sw_night -m -f -s[cartridges]soapSL.deps

And put it in a single script...then call that script from cron....

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Victor BERRIDGE
Honored Contributor

Re: problem in crontab execution

Im not sure to understand what you are doing...
If you want to set a variable that will be used by a job
Then my first reply applies or you can put the lot in the same script
the script would look like:
#!/bin/sh
export SW_PLATFORM=sol
export PATH=

echo $PATH 1>/dev/pts/52
echo "SET_PLATFORM: " $SW_PLATFORM 1>/dev/pts/52

/opt/softwire/develop/scripts/sw_admin runregression -proj cartridges -file cartridges/release/generic/scripts/sw_night -m -f -s[cartridges]soapSL.deps

#end

All the best
Victor



dawood_2
New Member

Re: problem in crontab execution

I tried the solution given and received the following error
---------------------------------------------

Your "cron" job on antriksh
(export SW_PLATFORM=sol;echo $SW_PLATFORM 1>/dev/pts/52;/opt/softwire/develop/scripts/sw_admin runregression -proj cartridges -file cartridges/release/generic/scripts/sw_night -m -f -s[psi_cartridges]soapSL.deps)

produced the following output:

sh: SW_PLATFORM=sol: is not an identifier

---------------------------------------------

is there any other way ?

Thanks
Dawood
Simon Hargrave
Honored Contributor

Re: problem in crontab execution

What does having this entry do: -

* * * * * (export SW_PLATFORM=sol;echo $SW_PLATFORM)

That should work fine (I have tested this). If that works, then the problem must lie in some way with the actual sw_admin command you are running. Unfortunately without knowing what/how this is supposed to work I don't know what to suggest. Only thing, perhaps your [ ] brackets are causing confusion in some way. Is the format of that command definately correct?
dawood_2
New Member

Re: problem in crontab execution

Thanks Guys.

It worked. I moved all my commands into one script and executed at one stretch.

Thanks again for your time.

Dawood
Alexander M. Ermes
Honored Contributor

Re: problem in crontab execution

Hi Dawood.
What about assigning some points to the people, that helped yu solve your problems ?
Rgds
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
dawood_2
New Member

Re: problem in crontab execution

Hi Alexander,

I have already assigned points to the responders.

Thanks,
Dawood