Using Zorin on a couple public access computers, and am having trouble getting a cron job to run, purpose is to shut the computer down after hours. Bios can turn it back on.
Session is run under a guest user without admin privileges, and the usual solutions such as
00 10 * * * sudo shutdown -h now
don't seem to work.
Guest is not member of sudoers group, wonder if making them a member is a good idea?
I've of course checked all the Ubuntu forums for answers, nothing seems to work.
The rest of the cron job runs fine. (I use bleachbit preset to delete some files and folders, and a shell script to restore my home folders)
There's an easier way... a kernel parameter which makes the OS 'stateless'... I was just reading about it today... let me see if I can find if again.
[EDIT]
Mheh... I can't find it. It was a Grub parameter, it allowed the OS to save files (so you could update it), but user changes were saved to volatile storage (RAM) and were wiped when the machine rebooted.
Whew! Wasn't sure that was going to work. If you get a chance, peruse the Grub man pages, I know I saw a parameter in there that lets the OS save files, and the users can make changes but they're wiped when the machine reboots... that'd make your task a lot easier. I think that's what that Intel Clear Linux does.
Interesting concept. If what I have with the addition of the shutdown works, I'm going to have to go with it. I'm running short of days left here, and need to get this stuff buttoned up.
Thanks again, I will check out the grub man pages and see what that's about.
I find it hard to believe that while an user can shutdown a system at the click of a button, it's this hard to script the action without running into these permissions issues.
I have added the user to the admin group, and using the user pwd in the script allows the command to work. Of course, this isn't the best from a security point of view. Considering the users, probably not too risky.
The shutdown command has already an embedded scheduler so you don't need a cron job for it to run at the specified time. In Linux as everywhere else, it's better to stick to the KISS principle (Keep It Short and Simple).
shutdown -h 22:00 will work fine, no need to run it in the background. Add the command at the end of /etc/rc.local (or /etc/rc.d/rc.local depending on your system) for execution in the last startup script.
The advantage of not using cron is that in this way the shutdown remains scheduled during the day, and you can cancel it at any time by typing
shutdown -c
Anyone know where the rc.local file or it's equivalent resides in Zorin?
Are you talking about where you put user executable scripts? /usr/local/bin
I'd just create a script that calls shutdown -h 22:00, make it executable, drop it into /usr/local/bin, then call it from Zorin menu > System Tools > Startup Applications.
As soon as the machine boots, it's got the command to shutdown at the specified time.
Or you can set it to run as a service, so the user never even sees any command prompt. Here's a quick how-to, used to remap the hard drive light to a keyboard light, but you can do the same for the shutdown command:
So let's say you want to name your script "autosd".
Create a text file with your shutdown script in it. Save it to /etc/init.d/autosd.
Set the file as executable: sudo chmod +x /etc/init.d/autosd
Create a sym-link in the proper run level directory: sudo ln -s /etc/init.d/autosd /etc/rc5.d/S01autosd
You want to use /etc/rc5.d, the 5th run-level, as that's the desktop... so as soon as the machine boots far enough to get to the graphical desktop, it'll have a command to shut down at the specified time.
You might want to put a wall message so anyone still using the machines don't freak out when it shuts down on them.
On my test run, it didn't, but I'm in the sudo group
On the public machines, I'll pull the guest out of that group and see what happens.
A terminal window is ok, as long as no input is needed.
The action will run afterhours, when nobody is at the computers.
The computers start up again in the am via the pc bios.
I read up on the why this poweroff issue is this way, goes way back to multi-user computers.