1827293 Members
3614 Online
109717 Solutions
New Discussion

Re: script problem

 
kholikt
Super Advisor

script problem

Hi,

I need to run some script to kill the ITO agents. However, this script will only run well if I run it manually. Through cron it will run the command never take effect. Anyidea.

#!/usr/bin/sh
/opt/OV/bin/OpC/opcagta -kill
abc
10 REPLIES 10
Georg Tresselt
Honored Contributor

Re: script problem

try to run the script through

su - root /path/script
http://www.tresselt.eu
Jean-Luc Oudart
Honored Contributor

Re: script problem

Hi

This is a classic question. Search for cron, plenty of posts.

The usual problem is that through cron the environment is not set. Therefore, you must set all required variables to run the specific script.

Regards
Jean-Luc
fiat lux
Stephen Keane
Honored Contributor

Re: script problem

When you run a script using cron it doesn't have the same environment (environment variables etc) as when you run it when you are logged in. If you add an 'env' call to your script you could compare the environments to see if there is something missing.


Also cron isn't interactive, so if your kill command prompts the user for anything, it will either hang, or throw an error.
Simon Hargrave
Honored Contributor

Re: script problem

Add the following line before your kill: -

. /opt/OV/bin/ov.envvars.sh

This will setup the environment for OpenView. You'll find that this is either in roots .profile or /etc/profile, which won't get run by your cron job.
Gopi Sekar
Honored Contributor

Re: script problem


few things to ensure.

* make sure you have executable permission for the script
* make sure to give full path for the script when you are calling from cron
* just to make sure that cron is actually calling the script, try to echo some test data to a temporary file and see whether it works

eg: echo `date` >> /tmp/test-cron-file

Regards,
Gopi
Never Never Never Giveup
Muthukumar_5
Honored Contributor

Re: script problem

The problem is, cron scheduled will be executed as cron user. By manually, you can able to do because you are logged with same user which starts that process.

You can do this as,

su - -c /opt/OV/bin/OpC/opcagta -kill

It will work. By default for root user, it will ask password. You can use sudo or expert script to do this easily with cron.

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: script problem

It is not expert. It is except scripting to expect passwd: and putting the su password in it.
Easy to suggest when don't know about the problem!
Alex Lavrov.
Honored Contributor

Re: script problem

It's probably environment problem. In crontab the environment is different, so something missing. 2 things:
1. add this line:
. /etc/profile
2. add some logging:
/opt/OV/bin/OpC/opcagta -kill > /tmp/my.log 2>&1

And see if there any error in the log file.


Let us know if it works.


Alex.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
renarios
Trusted Contributor

Re: script problem

Hi,

There is probably an environment variable missing.
What is the output of the job?
If you don't have that, cron the job like:
/opt/OV/bin/OpC/opcagta -kill 1>/tmp/output 2>&1

Please post the output.

Cheerio,

Renarios

Nothing is more successfull as failure
Joseph Loo
Honored Contributor

Re: script problem

hi,

not sure if it is an error on the script. it should be '/opt/OV/bin/OpC/opcagt -kill' without the 'a' after opcagt.

also, ensure that execute permission is granted for the user executing that script.

scheduling as a cronjob works for me.

regards.
what you do not see does not mean you should not believe