LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-07-2004, 11:22 PM   #16
nitin_batta
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat Enterprise Server 2.1
Posts: 96

Rep: Reputation: 15

Quote:
I made sure that I su'ed before typing crontab -e. But nothing seems to happen unless I'm logged in as root.
You mean to say you did :

Code:
$su - 
Password : xxxx
#crontab -e
That is the way to do it and then log off.

Crontab will execute all commands under the root privilidges.

Also you can look at the logs in /var/log/messages to check it cron throws an error while running it.
 
Old 09-09-2004, 02:47 PM   #17
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by nitin_batta
You mean to say you did :

Code:
$su - 
Password : xxxx
#crontab -e
That is the way to do it and then log off.

Crontab will execute all commands under the root privilidges.
Yep. To be more precise, this is what I did:
1.) I typed "su"
2.) I entered the password.
3.) I typed "crontab -e".
4.) I added the line to shut the computer down.
5.) I saved.
6.) I typed "crontab -l" to verify. Everything okay.
7.) I typed "exit".

But nothing happened when it was supposed to shut down.

Quote:
Originally posted by nitin_batta
Also you can look at the logs in /var/log/messages to check it cron throws an error while running it.
I did a "cat /var/log/messages | grep cron " (under root of course) and nothing showed up except for "crond startup/shutdown succeeded" messages. Nothing to do with my particular cronjob.
 
Old 09-25-2004, 10:13 PM   #18
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
bump

I even decided to use KCron to add the command graphically to my crontab but when 1am rolls around, nothing happens.

Anyone?
 
Old 09-27-2004, 10:21 AM   #19
sjspig
LQ Newbie
 
Registered: Mar 2003
Distribution: Modded-Knoppix
Posts: 23

Rep: Reputation: 15
Does the user the cron is running as have rights to shutdown the computer?
 
Old 09-27-2004, 01:17 PM   #20
Worstje
Member
 
Registered: Mar 2004
Distribution: Slackware-current
Posts: 93

Rep: Reputation: 15
Try using "su -", including the dash "-".
 
Old 09-27-2004, 05:22 PM   #21
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
Where and when do I type "su -"? It seems to do the same thing as "su".

What is "su -" supposed to do.

sjspig: The command should run as root even if the computer is logged on as a normal user.
 
Old 09-28-2004, 12:24 AM   #22
nitin_batta
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat Enterprise Server 2.1
Posts: 96

Rep: Reputation: 15
Quote:
Where and when do I type "su -"? It seems to do the same thing as "su".

What is "su -" supposed to do.
su will give you root privilidges but will not change and the home dir to root and also will not change environment varibles like PATH etc.

su - will also give you root priv along with setting home dir to root and also will also change environment varibles like PATH acc to the specified in the initialisation file (eg .bash_profile or .bashrc) etc.
 
Old 09-28-2004, 01:38 PM   #23
sjspig
LQ Newbie
 
Registered: Mar 2003
Distribution: Modded-Knoppix
Posts: 23

Rep: Reputation: 15
I think my reply was not worded correctly. Does the user for which the cronjob exists currently have rights to shutdown the box? In other words, can you shutdown the box logged in as the user that you are defining the cron job for?
 
Old 09-28-2004, 07:04 PM   #24
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by sjspig
I think my reply was not worded correctly. Does the user for which the cronjob exists currently have rights to shutdown the box? In other words, can you shutdown the box logged in as the user that you are defining the cron job for?
Hmm I assumed it doesn't matter, since it's not the user who's running the commands in root's crontab.

nitin_batta: I think I get it. But where would I use "su -"? I can't put it in crontab because it would ask for a password.
 
Old 09-28-2004, 07:25 PM   #25
sjspig
LQ Newbie
 
Registered: Mar 2003
Distribution: Modded-Knoppix
Posts: 23

Rep: Reputation: 15
You might use sudo instead - that way you could set up the exact command and let that user run that command when the cronjob is executed. Something like:

0 2 * * * /usr/sbin/sudo /usr/sbin/shutdown -h now

The user running the cronjob must have rights normally to shutdown the server. If you run /usr/sbin/shutdown -h now and the user can't shut the machine off then the user's crontab won't be able to either. There are other ways to make this work but the bottom line is that the user must have rights or it can't be done via crontab. Can you explain the user situation and if all of this sounds correct?
 
Old 09-30-2004, 02:46 PM   #26
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by sjspig
You might use sudo instead - that way you could set up the exact command and let that user run that command when the cronjob is executed. Something like:

0 2 * * * /usr/sbin/sudo /usr/sbin/shutdown -h now

The user running the cronjob must have rights normally to shutdown the server. If you run /usr/sbin/shutdown -h now and the user can't shut the machine off then the user's crontab won't be able to either. There are other ways to make this work but the bottom line is that the user must have rights or it can't be done via crontab. Can you explain the user situation and if all of this sounds correct?
But even when I'm a normal user, I can shutdown the computer from the GNOME desktop. However, "init 0" and "shutdown" don't work unless I am root. Is there a way I can get cron to run the GNOME shutdown command, which does not require root privileges?
 
Old 09-30-2004, 07:05 PM   #27
sjspig
LQ Newbie
 
Registered: Mar 2003
Distribution: Modded-Knoppix
Posts: 23

Rep: Reputation: 15
I don't know the exact process the gnome desktop uses to shutdown, but I imagine that is does something funky behind the scenes to make this work for you. Your best bet to do this command line is to use sudo and have it run the specific command in sudo. You could also just modify the crontab for root and have root shutdown when you want instead.
 
Old 10-01-2004, 03:04 PM   #28
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by sjspig
I don't know the exact process the gnome desktop uses to shutdown, but I imagine that is does something funky behind the scenes to make this work for you. Your best bet to do this command line is to use sudo and have it run the specific command in sudo. You could also just modify the crontab for root and have root shutdown when you want instead.
All the crontab modifications I've mentioned so far were to root's crontab. I su, then I do crontab -e, save, exit. I am wondering if root's crontab will only run if I am logged in as root.
 
Old 10-03-2004, 11:39 PM   #29
nitin_batta
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat Enterprise Server 2.1
Posts: 96

Rep: Reputation: 15
Hi can you post your crontab entry that you are trying .
Acc to me whena cronjob is run the command does not get executed with the rights of crontab userr it gets executed under the priv of the user (root in your case) under whose name the crontab is set.

To just do a check you can try and set the suid bit on the shutdown binary.

Hope this shld work as now any user can shutdown the system from cli

 
Old 10-09-2004, 01:40 AM   #30
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
How do I change the suid on a binary?

The crontab entry is 0 1 * * * init 0

I have also tried

0 1 * * * /sbin/init 0
0 1 * * * "/sbin/init 0" (so the path is not the problem)
0 1 * * * /sbin/shutdown -h now
0 1 * * * "/sbin/shutdown -h now" (so using a diff. command is not the problem)

None have worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running Screen in a cron job LinuxGeek Linux - Software 1 08-03-2005 12:11 AM
script not running as a cron job sanjith11 Programming 5 11-23-2004 08:42 AM
Cron job not running in slackware9.1 marri Linux - Software 2 05-06-2004 06:54 AM
Cron job not running? james_cwy Linux - Newbie 6 12-14-2003 08:24 PM
Cron Job Not Running pzorn Linux - General 4 10-02-2003 01:38 PM


All times are GMT -5. The time now is 07:32 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration