Rebooting Linux machine at midnight everyday

Discussion and support for all Linux distributions and Unix flavours (FreeBSD, OpenBSD, etc).
Post Reply
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Rebooting Linux machine at midnight everyday

Post by Hex_Rated »

Has someone got any ideas?

I need to automatically reboot a server everyday at midnight and it has do so before the login prompt (ie the computer boots and is left alone at the login prompt). The server is running a late version of RedHat. It has an application called KCron in Gnome which doesn't work. The command I'm trying to schedule for execution is /sbin/shutdown -r 23:59 but it doesn't run it, even if I'm logged in.

If I enter shutdown -r 23:59 manually in the terminal, it works. I have also tried to place this command in /etc/rc.d/rc.local without success. All my other programs run successfully called from rc.local, they run in the background before any user has logged on.

Any help would be greatly appreciated!
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
IcePick88
Registered User
Posts: 1341
Joined: 18 Mar 2008, 02:00
Location: KZN
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by IcePick88 »

CPU: AMD Phenom II X2 555 (OC'ed to 3.8Ghz)
CPU Cooler: CM Hyper TX3 P/P
GPU: Sapphire Radeon HD5850
Motherboard: Asus M4A785T-M
Memory: 4GB Corsair XMS3 DDR3 1333
Case: Zalman Z7
Display: Samsung Syncmaster 2243BWX
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by Hex_Rated »

Linux, please. That's for Windows.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
UrBaN
Registered User
Posts: 12811
Joined: 02 Feb 2005, 02:00
Location: JHB East
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by UrBaN »

Hex I am no Linux fundie, but maybe it is failing to run as it doesn't have the credentials?

I'm thinking a Linux equivalent of "Run as..."
Image
to ápeiro anima
Vampyre_2099
Registered User
Posts: 1321
Joined: 04 Nov 2007, 02:00
Location: /home/jhb/fourways

Re: Rebooting Linux machine at midnight everyday

Post by Vampyre_2099 »

and you can't make a shell script to run it?

Code: Select all

#! /bin/sh
shutdown -r 23:59
put that into a script, save script then make executable, then add that to the rc.local?

otherwise try use cronjob/crontab Wikipedia Cron

edit: As urban said, may be that only root can exec shutdown, so you need a way to exec the script as root
mybrute
myminicity
PCformat ZA Folding Stats

ImageImage
Spoiler: (show)
Desktop: Q8200 @ 2.33GHz ~ TRUE ~ DP35DP ~ 4GB Transcend Jetram RAM ~ Nvidia 8800GT ~ 250GB HDD
Notebook: T5550 @ 1.83GHz ~ 2GB RAM ~ ATI HD 2400 XT ~ 160GB HDD
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by Hex_Rated »

I'm running it as root but thanks for the ideas. I will try them.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by rustypup »

correct... anacron and "init 6", if you want to force the issue, else a simple shutdown script, (root owned)...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by Hex_Rated »

OK sorted. When I first tried to set it up I messed up the boot by putting shutdown -r 23:59 in rc.local without an & afterwards so the PC couldn't boot (without the & the shutdown will block continued execution).

Another guy "fixed" the rc.local file for me by booting with a USB drive and editing the file. Whatever he used to edit the file removed the execution rights on rc.local for all users which completely prevented rc.local from running at start up. Executing "chmod a+x rc.local" fixed the problem...

This is one of the reasons I would prefer to stay away from Linux. It would be fine if it wasn't for work and I was just messing around but this tiny, little problem cost me a few hours.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by Hex_Rated »

rustypup wrote:correct... anacron and "init 6", if you want to force the issue, else a simple shutdown script, (root owned)...
Thanks, I'll remember that for the future if I ever want to schedule something else.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by rustypup »

Hex_Rated wrote: this tiny, little problem cost me a few hours.
:lol: ouch...

one of the reasons we don't run as root... :wink: bypassing these controls generally results in drama....
Most people would sooner die than think; in fact, they do so - Bertrand Russel
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: Rebooting Linux machine at midnight everyday

Post by SBSP »

rustypup wrote:correct... anacron and "init 6", if you want to force the issue, else a simple shutdown script, (root owned)...
Wont Init 6 shut it down as in switch off ?

When you use kcron. When are you running the schedule? cus you are already scheduling the shutdown command at 23:00
so cron runs the command at 23:00 and a second later you tell it to run at 23:00 so it will shut down only the next day.
Which it probably wont cus of the reboot.

Why not run the shutdown command at start up ?
so everytime it starts up it will issue the shutdown command for 23:00
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by rustypup »

SBSP wrote:Wont Init 6 shut it down as in switch off ?
6 is reboot... unless red hat makes its own init rules in this regard....

and the real issue was someone had removed exec rights from the rc script... hence its being ignored at boot...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Re: Rebooting Linux machine at midnight everyday

Post by RuadRauFlessa »

SBSP wrote:
rustypup wrote:correct... anacron and "init 6", if you want to force the issue, else a simple shutdown script, (root owned)...
Wont Init 6 shut it down as in switch off ?
Nope that is init 0
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
Kasyx
Registered User
Posts: 139
Joined: 13 Dec 2006, 02:00

Re: Rebooting Linux machine at midnight everyday

Post by Kasyx »

Hex_Rated wrote:This is one of the reasons I would prefer to stay away from Linux. It would be fine if it wasn't for work and I was just messing around but this tiny, little problem cost me a few hours.
Don't blame the Linux, it was doing exactly what you told it to :P
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by Hex_Rated »

Kasyx wrote:Don't blame the Linux, it was doing exactly what you told it to :P
Not really hey, editing a file shouldn't remove execution privileges.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: Rebooting Linux machine at midnight everyday

Post by SBSP »

I never really understand the permission thing.


I once got permission denied errors so i ran a chmod 777 *.* -R in the root (On a production Spamfilter)
After the reboot nothing worked. I still dont know why , all i know it i wont do it again.
Kasyx
Registered User
Posts: 139
Joined: 13 Dec 2006, 02:00

Re: Rebooting Linux machine at midnight everyday

Post by Kasyx »

SBSP wrote:I once got permission denied errors so i ran a chmod 777 *.* -R in the root (On a production Spamfilter)
After the reboot nothing worked. I still dont know why , all i know it i wont do it again.
Image
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by rustypup »

Hex_Rated wrote:editing a file shouldn't remove execution privileges.
the file wasn't edited... it was replaced, (by root - who is supposed to know what s/he's doing) - new documents in a *nix environment are created as non-executable by default, (for really obvious reasons).

@SBSP: that's the oldest joke in the book... if you really fell for it, you need to seek revenge on the individual who suggested it :twisted:
Most people would sooner die than think; in fact, they do so - Bertrand Russel
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: Rebooting Linux machine at midnight everyday

Post by SBSP »

rustypup wrote:
Hex_Rated wrote:editing a file shouldn't remove execution privileges.
the file wasn't edited... it was replaced, (by root - who is supposed to know what s/he's doing) - new documents in a *nix environment are created as non-executable by default, (for really obvious reasons).

@SBSP: that's the oldest joke in the book... if you really fell for it, you need to seek revenge on the individual who suggested it :twisted:
No one sugested it , like i said i got permission errors so i checked up on how to change permissions.
found that chmod 777 does this.

When i tried to install squid it kept telling me permission denied when i fix the problem i run the install again
it gave me permission denied errors on the next folder, kept fixing it for about 5 different directories.
So i got fed up and decided to do the whole drive.
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Re: Rebooting Linux machine at midnight everyday

Post by Hex_Rated »

rustypup wrote:
Hex_Rated wrote:editing a file shouldn't remove execution privileges.
the file wasn't edited... it was replaced, (by root - who is supposed to know what s/he's doing) - new documents in a *nix environment are created as non-executable by default, (for really obvious reasons).
I use Kate to edit files under normal circumstances and execution rights aren't removed. But yeah, I get what your saying. I'll give root a good kick up the a$$ next time he walks past my office.
@SBSP: that's the oldest joke in the book... if you really fell for it, you need to seek revenge on the individual who suggested it :twisted:
Linux equivalent of delete system32 to make your PC faster.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: Rebooting Linux machine at midnight everyday

Post by SBSP »

Linux equivalent of delete system32 to make your PC faster.
thanks now my PC is broken. :lol:
Ryan_Cooper
Registered User
Posts: 3129
Joined: 22 Sep 2008, 11:16
Location: stuck in my own world

Re: Rebooting Linux machine at midnight everyday

Post by Ryan_Cooper »

type crontab -e if you have it on your system and put in this line
23 00 * * * /sbin/init 0
and it should coz your machine to shutdown everyday at that time
i could have the exact command wrong though not quite sure if it doesnt work you could replace /sbin/init 0 with /sbin/shutdown -t now taht might work as well
THE GAME........YOU Have JUST LOst It !!!!!!!!!!
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Re: Rebooting Linux machine at midnight everyday

Post by SBSP »

Ryan_Cooper wrote:type crontab -e if you have it on your system and put in this line
23 00 * * * /sbin/init 0
and it should coz your machine to shutdown everyday at that time
i could have the exact command wrong though not quite sure if it doesnt work you could replace /sbin/init 0 with /sbin/shutdown -t now taht might work as well
I think the problem is sorted :wink:
Post Reply