How to run a script as different user inside cronjob in solaris.


 
Thread Tools Search this Thread
Operating Systems Solaris How to run a script as different user inside cronjob in solaris.
# 1  
Old 12-14-2007
How to run a script as different user inside cronjob in solaris.

Hi ,

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.

Thanks &Regards,
csg_user
# 2  
Old 12-14-2007
Sudo gives you the option to allow a user to run commands without a password (ie. not requiring confirmation).

The alternative is to put the actions in root's crontab and use "su - user -c command".
# 3  
Old 12-14-2007
Quote:
Originally Posted by csg_user
.I have provded 777 permissions for that script .
*Never* do this, especially when using cron. It allows anyone to alter the script to perform tasks as that user.
# 4  
Old 12-14-2007
Quote:
Originally Posted by csg_user
This script normally requires to be run as a different user.
or put the script in that user's crontab.
# 5  
Old 12-15-2007
Hi Prowla,
Thanks for your reply .
Quote:
Originally Posted by prowla
The alternative is to put the actions in root's crontab and use "su - user -c command".

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.
# 6  
Old 12-15-2007
Quote:
Originally Posted by porter
or put the script in that user's crontab.
Hi Porter,

Thanks. I tried running the script under that user's cron . But, it is not working . Am i missing something here?

Thanks.
# 7  
Old 12-15-2007
Quote:
Originally Posted by csg_user
I tried running the script under that user's cron . But, it is not working . Am i missing something here?
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

2. UNIX for Dummies Questions & Answers

Script does not run from a user specific cronjob.

Hello, I have two crontabs, one for the root and one for another user. There is a script in my configurations that has to send a email. The script works and sends the emails when I run it by hand with either the root or the user, and when I program it in the root's crontab. But! It does not... (3 Replies)
Discussion started by: Tralaraloro
3 Replies

3. Shell Programming and Scripting

Schedule and Run By weekly shell script in cronjob

Hi All, How to schedule a shell script(script name- byweeklyreport.sh) it should run by weekly in corn job or is there any script have to write to check week and then run the above script. example-1st run March 06 2013 2nd run March 20 2013 3rd run April 3 2013... (13 Replies)
Discussion started by: krupasindhu18
13 Replies

4. Shell Programming and Scripting

Run .exe inside shell script

I have to run some shell scripts in Windows using Cygwin. I am able to achieve that using %BASH% --login -i "/cygdrive/d/script.sh" , where %BASH% is an environment variable in Windows set to C:\cygwin\bin\bash.exe. I have a created a Cygwin environment variable $EXE_PATH =... (3 Replies)
Discussion started by: HemanthJayasimh
3 Replies

5. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

6. Shell Programming and Scripting

Running script that sends an html formatted email fails when its run as cronjob

Hi Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem. Im... (15 Replies)
Discussion started by: Nightowl
15 Replies

7. UNIX for Dummies Questions & Answers

cronjob to run perl script

Hi all Recently i had finished a perl script. When i run manually, the script work fine. But when i wanted to put the script in cron, it didn't get the same output as it run manually. I felt that it only execute the script until certain line then it stop as i see most of the related files didn't... (6 Replies)
Discussion started by: AirWalker83
6 Replies

8. Shell Programming and Scripting

Run the command inside perl script

I have a command which will run fine in a unix command prompt. Can you tell how to interprete this command inside perl script...... The command is : perl -pe 's/(\|333\}.*)\}$/$1|1.6}/' FIA.txt This will search for the number 333 and appends 1.6 at the end of that line....... (1 Reply)
Discussion started by: vinay123
1 Replies

9. Shell Programming and Scripting

cronjob inside the script

Hiii, can nayone provide me the sample script which can do the following tasks--- I will apperciate if anyone give me their valuable inputs.I guess this is not at all a big task for the experts in the forum so kindly help me out in this. (3 Replies)
Discussion started by: namishtiwari
3 Replies

10. Shell Programming and Scripting

How to run an SQL script inside a shell

How do I create a K Shell which would silently (without user input) logon to Oracle and run an SQL script? Any help will be greatly appreciated. Steve (1 Reply)
Discussion started by: stevefox
1 Replies
Login or Register to Ask a Question