Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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.
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?
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?
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.
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.
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
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)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.