Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

will crontab work if diff user logged in?

Status
Not open for further replies.

cyberant

Programmer
Sep 21, 2003
44
ZA
I've set up a crontab schedule that backs up my database at 2 in the morning. Everything is working fine, so long as I'm logged as the user who created the crontab schedule, but if not, it doesn't seem to work.

Am I missing something? What would I need to do to have a crontab scheduled but not necessarily be logged on as that user?
 
I would run the job as root, but preface the command you want to run with /bin/su uSeRnAmE -c 'command you want to run'
Hope that helps :eek:)
 
well, is the crontab set up in the main /etc/crontab file, or the users crontab??

___________________________________
[morse]--... ...--[/morse], Eric.
 
I'm not sure. I simply issued the command at the console, while logged in as a particular user. What would the difference between the two options be in terms of allowing me run a different users crontab? Are you saying that if the crontab is issued in the /etc/crontab file then the commands are issued across the user list, regardless of who's logged in?
 
AFAIK, cron runs for whatever user whether logged in or not. You may have environment issues if your job isn't running as expected. Try setting the PATH explicitly within the script.
 
Where is the best place to set the path? I'm having trouble restarting a service and I assume that it's because I'm not logged in as root. Is there a way to change the restrictions on my account to allow for this, or should I simply change the user in the command input?
 
If you're using the su - <user> -c "command" type of cron entry, set the PATH in the user's .profile. Otherwise (and if possible) set the PATH in the script itself or use a 'wrapper' to set the PATH then execute the script. HTH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top