LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-08-2012, 08:06 AM   #1
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Can't define daily automatic shutdown with crontab


Hi,

I want to define a daily automatic shutdown of all client PCs here, every evening at 10 PM, since more often than not, folks forget to shutdown their PC.

I launched crontab -e and then added the following line:

Code:
00 22 * * * /sbin/shutdown -h
This seemed to have no effect. I wonder if there's something else to do for the action to take effect.

Note: I edited the crontab file a few minutes before 10 PM, don't know if this has any influence.

Any suggestions?
 
Old 10-08-2012, 08:14 AM   #2
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
I'll answer this myself, since I just found the solution. I simply forgot to add 'now' as argument to 'shutdown -h'.

Works OK now.
 
Old 10-08-2012, 09:43 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Something else you can do is, in a root crontab only, use
Code:
00 22 * * * /sbin/init 0
That'll shut down and power off the machine right quick (and clean).

If, for some odd reason or other, you wanted to reboot at some time (I dunno why but people do actually do this sort of thing on a daily basis):
Code:
00 22 * * * /sbin/init 6
Different strokes...

Hope this helps some.
 
Old 10-08-2012, 11:38 AM   #4
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Do not use `init` to change runlevels -- use `telinit`. See `man init`. Using `init` may work, but it is poor form. Off-topic since the problem is solved, but I felt I needed to correct an error I see all too often.
 
Old 10-08-2012, 01:24 PM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
Originally Posted by T3slider View Post
Do not use `init` to change runlevels -- use `telinit`. See `man init`. Using `init` may work, but it is poor form. Off-topic since the problem is solved, but I felt I needed to correct an error I see all too often.
Beg to disagree:
Quote:
/sbin/telinit is linked to /sbin/init. It takes a one-character argument and sig-
nals init to perform the appropriate action. The following arguments serve as
directives to telinit:

0,1,2,3,4,5 or 6
tell init to switch to the specified run level.

a,b,c tell init to process only those /etc/inittab file entries having runlevel
a,b or c.

Q or q tell init to re-examine the /etc/inittab file.

S or s tell init to switch to single user mode.

U or u tell init to re-execute itself (preserving the state). No re-examining of
/etc/inittab file happens. Run level should be one of Ss12345, otherwise
request would be silently ignored.

telinit can also tell init how long it should wait between sending processes the
SIGTERM and SIGKILL signals. The default is 5 seconds, but this can be changed
with the -t sec option.

telinit can be invoked only by users with appropriate privileges.

The init binary checks if it is init or telinit by looking at its process id; the
real init's process id is always 1. From this it follows that instead of calling
telinit one can also just use init instead as a shortcut.
So, for the sake of curiosity, just what poor form are we talking about here? Been shutting down or rebooting Unix and Linux systems with init runlevel for, oh, 35+ years, never had a problem.
 
Old 10-08-2012, 02:15 PM   #6
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
In many cases (Slackware included) init is a symlink to telinit and init detects the pid being run anyway, so it makes no difference. This was added for convenience, but on other UNIX systems this may not be the case. On some Linux systems using a non-SysV init, init and telinit are two different binaries (though usually init will recognize the erroneous call and pass to telinit anyway). Again, using init may work, but it is poor form, is non-standard, is not guaranteed to remain compatible (though I don't see it changing on Linux), and may not work on other UNIX systems. It is 'poor form' despite working properly, as I stated. You lose nothing by using telinit instead of init.
 
2 members found this post helpful.
Old 10-08-2012, 03:58 PM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by T3slider View Post
on other UNIX systems this may not be the case. On some Linux systems using a non-SysV init, init and telinit are two different binaries... but it is poor form, is non-standard, is not guaranteed to remain compatible
Thanks for the simple explanation. I always use telinit out of long habit, but would not have known why not to use init if asked - now I do!
 
  


Reply

Tags
cronjob, crontab, shutdown



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
Crontab or cron.daily? PlatinumX Linux - Newbie 1 11-09-2010 02:21 AM
Howto schedule shutdown daily drsethi SUSE / openSUSE 1 04-29-2009 12:26 PM
help me understand the difference between cron.daily and crontab -e duderancher Linux - Software 7 10-09-2008 11:53 AM
automatic shutdown muhammednavas Fedora 1 12-01-2006 10:48 AM
crontab vs cron.daily ? SheldonPlankton Linux - Newbie 1 07-16-2004 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:57 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration