The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > SUN Solaris
Google UNIX.COM


SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cronjob inside the script namishtiwari Shell Programming and Scripting 3 02-04-2008 04:35 AM
HOw do i give a user cronjob edit/settings permission? debu UNIX for Advanced & Expert Users 2 01-24-2008 01:44 AM
help help cronjob problem with script bucci Shell Programming and Scripting 4 02-10-2007 12:38 AM
cronjob dies when user password expires sparcguy SUN Solaris 4 02-04-2007 11:04 PM
switch user inside a script nimo Shell Programming and Scripting 2 11-04-2005 03:51 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-14-2007
Registered User
 

Join Date: Dec 2007
Posts: 5
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-14-2007
Read Only
 

Join Date: Nov 2007
Posts: 165
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".
Reply With Quote
  #3 (permalink)  
Old 12-14-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,503
Quote:
Originally Posted by csg_user View Post
.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.
Reply With Quote
  #4 (permalink)  
Old 12-14-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by csg_user View Post
This script normally requires to be run as a different user.
or put the script in that user's crontab.
Reply With Quote
  #5 (permalink)  
Old 12-15-2007
Registered User
 

Join Date: Dec 2007
Posts: 5
Hi Prowla,
Thanks for your reply .
Quote:
Originally Posted by prowla View Post
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.
Reply With Quote
  #6 (permalink)  
Old 12-15-2007
Registered User
 

Join Date: Dec 2007
Posts: 5
Quote:
Originally Posted by porter View Post
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.
Reply With Quote
  #7 (permalink)  
Old 12-15-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by csg_user View Post
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.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0