VectorLinux
October 22, 2014, 06:38:15 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1] 2
  Print  
Author Topic: how do I autoshutdown with cron  (Read 7146 times)
startreksteve
Member
*
Posts: 13


« on: April 28, 2008, 04:51:54 am »

OK,
I setup my 3 year old son with Vector 5.9 for his educational games & Cbeebies Website. trouble is, when he's finished, he flicks the monitor off and leaves the cpu humming away. Its a Celeron 400 with 390MB memory, it powers down ok from the taskbar button, I want to schedule a shutdown with Cron. I enabled cron in VASM, & entered this line in /etc/cron
30 18 * * 1-7 root /sbin/shutdown -s now!

This is the syntax I use in Ubuntu, is it valid for Vector Linux?
Logged

Celeron 700 Laptop 256mb running Vector 5.9
3 year-old Sons' Celeron 400 320mb 20GB HD running Vector 5.9
saulgoode
Vectorite
***
Posts: 340



« Reply #1 on: April 28, 2008, 06:04:43 am »

30 18 * * 1-7 /sbin/shutdown -h now

Vector (and Slackware) run a minimal cron daemon and you shouldn't specify "root" in the crontab (just make sure the cron job belongs to root). Also, the exclamation mark is unnecessary (and will cause an error).

--------------------------------

Alternatively, you could edit your rc.local to execute (upon bootup) a scheduled shutdown:

echo "/sbin/shutdown -a -h 18:30 &" >>/etc/rc.d/rc.local

If you wished to permit your son to cancel such a scheduled shutdown, you could do so by adding him (as well as yourself and any other authorized users) to '/etc/shutdown.allow'. If you don't wish to authorize your son to cancel the shutdown, you would remove the "-a" option from the above line. Canceling shutdown is performed by '/sbin/shutdown -c'.







« Last Edit: April 28, 2008, 06:06:22 am by saulgoode » Logged

A complex system that works is invariably found to have evolved from a simple system that works.
startreksteve
Member
*
Posts: 13


« Reply #2 on: April 28, 2008, 07:15:56 am »

How do I make sure that Cron belongs to root?
Logged

Celeron 700 Laptop 256mb running Vector 5.9
3 year-old Sons' Celeron 400 320mb 20GB HD running Vector 5.9
bigpaws
Vectorian
****
Posts: 1856


« Reply #3 on: April 28, 2008, 07:45:10 am »

Editing as root is all you need.

man crontab for more information

Bigpaws
Logged
The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1551


I like the bass to go BOOM!


WWW
« Reply #4 on: April 28, 2008, 08:38:43 am »

I'd like to point out that the Howto section is not meant for posting questions, but for finished HOWTO's . Moving it to "Software general" instead
Logged

Most music on my soundcloud page was arranged in programs running on VL.
startreksteve
Member
*
Posts: 13


« Reply #5 on: April 28, 2008, 10:54:14 pm »

Ok I tried the action below:

Alternatively, you could edit your rc.local to execute (upon bootup) a scheduled shutdown:

echo "/sbin/shutdown -a -h 18:30 &" >>/etc/rc.d/rc.local

and it worked perfectly,... BUT....

when I try to do a manual shutdown via the taskbar, it doesnt shutdown, it restarts! over and over again, I cant shut down except my command line!!
cant figure it out.
Steve
Logged

Celeron 700 Laptop 256mb running Vector 5.9
3 year-old Sons' Celeron 400 320mb 20GB HD running Vector 5.9
saulgoode
Vectorite
***
Posts: 340



« Reply #6 on: April 29, 2008, 03:11:59 am »

It would seem you have uncovered a critical flaw in my proposed strategy. Of course, there would be ways to circumvent the problem but they would likely be uncomely and hackish. I would advise pursuing the CRON approach.
Logged

A complex system that works is invariably found to have evolved from a simple system that works.
startreksteve
Member
*
Posts: 13


« Reply #7 on: April 29, 2008, 10:13:12 am »

Ok, so what am I doing wrong?
I use cron all the time in ubuntu...
if I type crontab -e in a terminal, I get an unfriendly screen I cant ebter any data into,
If I enter SU and go into root
enter nano crontab and enter the following:
30 18 * * 1-7 /sbin/shutdown -h now
then do CTRL -X to save
nothing executes...
cron in enabled in VASM, dont know where else to look.
TIA
Steve
Logged

Celeron 700 Laptop 256mb running Vector 5.9
3 year-old Sons' Celeron 400 320mb 20GB HD running Vector 5.9
bigpaws
Vectorian
****
Posts: 1856


« Reply #8 on: April 29, 2008, 12:03:51 pm »

crontab -e opens crontab in vim text editor which can
be used to add your command.

Bigpaws
Logged
startreksteve
Member
*
Posts: 13


« Reply #9 on: April 29, 2008, 10:44:47 pm »

How?
whats the Add command? Ive tried CTRL +A and various combinations, its starting to annoy me now!
« Last Edit: April 30, 2008, 06:57:36 am by startreksteve » Logged

Celeron 700 Laptop 256mb running Vector 5.9
3 year-old Sons' Celeron 400 320mb 20GB HD running Vector 5.9
saulgoode
Vectorite
***
Posts: 340



« Reply #10 on: April 29, 2008, 11:49:04 pm »

If you wish to use 'nano' to edit your crontab, you need to specify nano as your editor. This can be done by setting the VISUAL environment variable to nano on the same line that you invoke 'crontab -e'.

VISUAL=/usr/bin/nano crontab -e

If wish to set up nano to be your preferred editor for other system operations (man sudoedit), you should append the following line to your users' ~/.bashrc files:

export VISUAL=/usr/bin/nano
Logged

A complex system that works is invariably found to have evolved from a simple system that works.
startreksteve
Member
*
Posts: 13


« Reply #11 on: April 30, 2008, 03:02:46 am »

I tried the above, and it opened a cron list of scheduled tasks, but it wouldnt let me add a new one! I must be doing something really basic & stupid, but Ive no idea what!
I use cron all the time in Ubuntu, no problems at all with starting & killing tasks on schedules. Can someone walk  me through this..
All i want to do is shutdown the pc at 18:30 daily.
Where should the crontab file be? Im doing SU first so I root, should the file be in "Steve's" home? or in homes Root? or somewhere else?
Steve
« Last Edit: April 30, 2008, 06:59:12 am by startreksteve » Logged

Celeron 700 Laptop 256mb running Vector 5.9
3 year-old Sons' Celeron 400 320mb 20GB HD running Vector 5.9
saulgoode
Vectorite
***
Posts: 340



« Reply #12 on: May 01, 2008, 04:30:40 am »

I believe the problem is that you are including the '-a' switch to the 'shutdown' command. When you specify '-a', shutdown will check to see if the user requesting the shutdown is currently logged in, and ignore the command if he is not. In your case (since you edited the crontab as root), if root is not logged into the system at the time of the scheduled shutdown then there will be no shutdown.

I tried the above, and it opened a cron list of scheduled tasks, but it wouldnt let me add a new one! I must be doing something really basic & stupid, but Ive no idea what!

You must add your line to the file you are editing (it is just a text file). If you are logged in as root then the file being edited (using 'crontab -e') is /var/spool/cron/crontabs/root. If you were logged in as 'steve' then the file being edited (using 'crontab -e') is /var/spool/cron/crontabs/steve. But you shouldn't have to worry about what file is being edited.

Only root is authorized to directly access the crontab files, which is why the 'crontab -e' command MUST be used by regular users to edit their crontab setup (with '-l' and '-d' options used to list and delete the crontab file).

« Last Edit: May 01, 2008, 04:36:16 am by saulgoode » Logged

A complex system that works is invariably found to have evolved from a simple system that works.
startreksteve
Member
*
Posts: 13


« Reply #13 on: May 02, 2008, 01:15:59 am »

Ok I tried editing /var/spool/cron/crontabs/root and /var/spool/cron/crontabs/steve with nano, and created the following entry:
30 18 * * 1-7 /sbin/shutdown -h
saved it ok, checked the cron and its in the list.
I enabled the cron service, and nothing runs.
Any ideas?
Logged

Celeron 700 Laptop 256mb running Vector 5.9
3 year-old Sons' Celeron 400 320mb 20GB HD running Vector 5.9
saulgoode
Vectorite
***
Posts: 340



« Reply #14 on: May 02, 2008, 02:09:35 am »

Do you mean nothing runs at 6:30PM? I.e., your computer doesn't shutdown at 18:30?

Logged

A complex system that works is invariably found to have evolved from a simple system that works.
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!