LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Can't define daily automatic shutdown with crontab (http://www.linuxquestions.org/questions/slackware-14/cant-define-daily-automatic-shutdown-with-crontab-4175431117/)

kikinovak 10-08-2012 09:06 AM

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?

kikinovak 10-08-2012 09:14 AM

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.

tronayne 10-08-2012 10:43 AM

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.

T3slider 10-08-2012 12:38 PM

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.

tronayne 10-08-2012 02:24 PM

Quote:

Originally Posted by T3slider (Post 4800421)
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.

T3slider 10-08-2012 03:15 PM

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.

astrogeek 10-08-2012 04:58 PM

Quote:

Originally Posted by T3slider (Post 4800565)
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!


All times are GMT -5. The time now is 09:27 PM.