I have a shell script to perform some actions on sun solaris box . This script normally requires to be run as a different user. so, whenever i have to run this script, i need to sudo in as that user , enter the password and execute it. Now,I have to setup a cronjob to execute the script every 15 mins .I have provded 777 permissions for that script .
But, that is not working inside the cronjob. I think the sudo is creating problems. Iam planning to create another script to call the original script .Is there a way to provide the password and the user id that i need to sudo in to run the script while running from a cronjob? Please advise how to handle this.
My cron will have :
0,15,30,45 * * * * /opt/myfolder/myscriptname. I will use the same under root's cron .But,Where should i use the "su - user -c command". Please let me know.
I don't know, I don't know what your script does or how you've set it up, but 99% of problems with crontab are due to environment variables not being initialised.
The script(script1) will recycle our application services. This script could only be executed as the application user . So, We run this script manually by sudo su - appl_user , then password , then run the script . $myscript name. Now , iam trying to automate it . So, iam calling in a cronjob .But, that is not working .
Actually, based on this result, i need to create another script(script2) which will call the script1 only if some application conditions are satisfied.
That is where the sudo/password for the appl_user is creating problems.
Confirm that script works from home directory of user you want it to run as when run from a terminal/ssh/telnet login.
That will prove if the user has all the rights etc.
Then do a "set" to print all the environment variables that are present before the script was run. Look through them and identify ones your script will need.
When the cron task runs assume none of those variables will be set (except a few, eg HOME).
As I said, 99% of cron problems are environment based.