Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 5th July 2011, 05:42 PM
sea's Avatar
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,602
linuxfirefox
Cron Shutdown, but not on weekend.

Hiyas

Just read through some cron manuals. (man -k cron).
Didnt understood that much though.

Situation:
I'm a gamer and loosing control over time at nights.
So what i want is that my computer shuts down itself at latest 1:30 am.

Anyway here's my question:
Do i need to set up the command for each day (monday, tuesday.. and so on) or is there an option simliar to my 'example' below?
€dit: Both examples should do the trick.
Code:
# m h  dom mon dow   command
30 1 * * 1,2,3,4,5 shutdown -h +5 Get some sleep dude!
30 1 * * 1-5 shutdown -h +5 Get some sleep dude!
Where as 1 to 5 would be all weekdays, but not saturday or sunday morning at 1:30am.
If i can shorten it to 1 line instead of 7 lines (one per day of week) that would be great.

Thanks in advance.

---------- Post added at 04:42 PM ---------- Previous post was at 04:15 PM ----------

Ok, google had the solution.
Found it at:
http://www.scrounge.org/linux/cron.html
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb

Last edited by sea; 5th July 2011 at 06:34 PM.
Reply With Quote
  #2  
Old 5th July 2011, 05:43 PM
Miikka's Avatar
Miikka Offline
Registered User
 
Join Date: Apr 2011
Location: Finland
Posts: 293
linuxfirefox
Re: Cron Shutdown, but not on weekend.

You can use 1-5 as the date option.

EDIT: too slow
Reply With Quote
  #3  
Old 5th July 2011, 06:32 PM
sea's Avatar
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,602
linuxfirefox
Re: Cron Shutdown, but not on weekend.

Thank you miika,
even slow, you gave another possible option
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
Reply With Quote
  #4  
Old 6th July 2011, 09:41 AM
sea's Avatar
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,602
linuxfirefox
Re: Cron Shutdown, but not on weekend.

Seems i do need more help

I created a file with the command:
Code:
echo "25 1 * * 1-5 shutdown -h +5 Get some sleep dude" > sleep.cron
crontab sleep.cron
crontab -l
Shows me the the one enrty i made with the file, so far it seems correct to me.
But the command was not executed, and i just dont know why

Also the message was not displayed.
Would there pop up a terminal window showing the message or some 'messagebox'?
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb

Last edited by sea; 6th July 2011 at 11:28 AM.
Reply With Quote
  #5  
Old 6th July 2011, 10:16 AM
pete_1967 Online
Clueless in a Cuckooland
 
Join Date: Mar 2006
Location: Here now, elsewhere tomorrow.
Posts: 3,928
linuxfirefox
Re: Cron Shutdown, but not on weekend.

A cronjob runs a job. Add actions (e.g. printing the message) to the file you want cron to run. Note that the task must be a script (e.g. bash script) or a program, if you want to send a message to user, you either need to use graphical toolkit or similar unless you expect them to have terminal open at all times. It will not open terminal to show anything unless your script opens it first.

Use crontab -e to edit your jobs, it's easier and safer.

Because you learn better by trying things rather than just copying and pasting, below are couple easier examples for you to follow:
http://www.thegeekstuff.com/2009/06/...ntab-examples/ and http://www.cyberciti.biz/faq/how-do-...-or-unix-oses/
__________________
A Drink is Not Just For Christmas - SaskyCom :thumb:


“Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime” so now go and...
RTFM FIRST: http://docs.fedoraproject.org/ & http://rute.2038bug.com/index.html.gz

Last edited by pete_1967; 6th July 2011 at 10:20 AM.
Reply With Quote
  #6  
Old 6th July 2011, 11:08 AM
sea's Avatar
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,602
linuxfirefox
Re: Cron Shutdown, but not on weekend.

Ok forget about the message, its there if i have a terminal open. I dont need that message, its just for fun at this moment.
/* EDIT: PS
I did have a terminal open at 1:30, actualy all the time from 10pm to 2am. But i didnt get any message there.
So, since i didnt get the message and i had to shutdown the computer myself, the command wasnt executed */


With the -e argument, all i got was that temp file, which wernt listed when checking with contrab -l.
Re used contrab -e, the entry i made was stored. but not applied to crontab -l.

While i used the way to create a file, and add that file to crontab, i get its result when crontab -e, however, again as tempfile, but now listed with crontab -l.

Again.

The job is there.
But wasnt executed.

Do i need to set the path variables for each and every cron job? I mean, i want to 'run' shutdown, which is a basic command (in this case).
Do i need to start cron somehow?
Isnt it a deamon that runs anayway?
Attached Thumbnails
Click image for larger version

Name:	shell-cron.png
Views:	42
Size:	55.0 KB
ID:	21395  
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb

Last edited by sea; 6th July 2011 at 11:34 AM.
Reply With Quote
  #7  
Old 6th July 2011, 11:38 AM
Smoking Tux's Avatar
Smoking Tux Offline
Registered User
 
Join Date: Jan 2011
Location: /home
Posts: 267
windows_xp_2003firefox
Re: Cron Shutdown, but not on weekend.

Only some guesses:

You're trying to add this job to a users crontab or roots one? Thats a difference in this case. You need root access to execute 'shutdown'.

Further you should give the full path for the command, e.g. /sbin/shutdown -h .
__________________
regards, Thomas
Reply With Quote
  #8  
Old 6th July 2011, 11:56 AM
sea's Avatar
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,602
linuxfirefox
Re: Cron Shutdown, but not on weekend.

Hmm guess i'll add it to the root jobs, as it requires root rights anyway.
So either i'll add the absolute path, or define the paths to look for the command.
Even for 'basic' commands, thought that applies only to 'custom' commands.

Thank you smoking
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
Reply With Quote
  #9  
Old 7th July 2011, 12:23 PM
sea's Avatar
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,602
linuxfirefox
Re: Cron Shutdown, but not on weekend.

Heyas

Its weird, it doesnt do nothing... I'm not even getting an email from cron that the job could not be done.
Currently i try it on Ubuntu, so for some reason that wont let me run a script as root = su: error with auth.

I wrote a 'testscript':
PHP Code:
#!/bin/bash
cd ~
echo 
"This cron worked" >> myCronTest 
Then i added this line to cron for myself:
PHP Code:
16 13 * * 1-/home/simon/test.sh 
To me its still confusing that it first wants minutes, then hours, so that script was planned to be run at 13:16, or 1:16pm.
Once again, it didnt work.
There is no 'new' file named "myCronTest" in my ~ directory.

€dit:
Sidenote: i used 2 diffrent ways to test cron, both started without -u or su or sudo.
1) crontab -e
2.a) create a file (sleep.cron) with the cron command in it
2.b) crontab sleep.cron
Neither of them worked.
Well, the command was added, as well as listed, but not executed.
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb

Last edited by sea; 7th July 2011 at 01:14 PM.
Reply With Quote
  #10  
Old 7th July 2011, 12:54 PM
scott32746 Offline
Registered User
 
Join Date: Jun 2007
Location: Lake Mary, Florida
Age: 48
Posts: 1,082
windows_xp_2003firefox
Re: Cron Shutdown, but not on weekend.

Hello,

become root

# crontab -e
Use vi commands

add
30 1 * * * /usr/bin/halt -p
This is going to power it off very day of the week
Reply With Quote
  #11  
Old 7th July 2011, 01:15 PM
sea's Avatar
sea Offline
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,602
linuxfirefox
Re: Cron Shutdown, but not on weekend.

Yeah right....
Does anyone read the followposts, after first?

Su wont work, with "# crontab -e" just goes to the next line in shell.
"su crontab -e" doesnt work either, "unrecognized command -- e"
Even with "su -c crontab -e" results in above error.
Only thing that DID work (to add it NOT to my profile) was "sudo crontab file-with-cron-command", which was claimed to be buggy on some page i read, or "sudo crontab -e".

Anyway...
Even the TESTSCRIPT which is a simple echo command doesnt work / is not executed.
So first i want my stupid "echo" to be executed.
Oh yeah, when executing the test.sh manualy, it creates the file: myCronTest.

As i dont see any diffrence of the syntax, could someone check the lines i've 'quoted'?
Just to approve that the command IS correct.

Or is "cron" a common issue on ubuntu?
-------------------------
I'm assuming its something diffrent, i dont think its the 'code' that doesnt work. Do i need to start cron? or is it by default a running deamon in background?
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb

Last edited by sea; 7th July 2011 at 01:22 PM.
Reply With Quote
  #12  
Old 7th July 2011, 01:36 PM
scott32746 Offline
Registered User
 
Join Date: Jun 2007
Location: Lake Mary, Florida
Age: 48
Posts: 1,082
windows_xp_2003firefox
Re: Cron Shutdown, but not on weekend.

The # is not part of the command
from your USER ID command prompt type

su -

once you get the root prompt " # "
then type

crontab -e

add your line

try adding " sh " to your line
EXAMPLE:
16 13 * * 1-7 sh /home/simon/test.sh




also check file
/etc/cron.deny make sure it does not have any ID you want to have cron enable not in there
Reply With Quote
  #13  
Old 7th July 2011, 01:53 PM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105
linuxfedorafirefox
Re: Cron Shutdown, but not on weekend.

Ummm...

One thing you need to know that is not necessarily reported...

during shutdown, one of the first things stopped is cron itself.

Which in turn will stop the shutdown.

You might have better luck to detach the shutdown from cron (see manpage on "nohup").
Reply With Quote
  #14  
Old 7th July 2011, 02:01 PM
scott32746 Offline
Registered User
 
Join Date: Jun 2007
Location: Lake Mary, Florida
Age: 48
Posts: 1,082
windows_xp_2003firefox
Re: Cron Shutdown, but not on weekend.

I shutdown my server very night at midnight by cron without problems

Once the shutdown/halt has been started cron can be stopped with out stopping shutdown.
This because the shutdown command is going to have it's own process number/id and not the process number/id of cron.
Reply With Quote
  #15  
Old 7th July 2011, 02:13 PM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105
linuxfedorafirefox
Re: Cron Shutdown, but not on weekend.

It isn't that you get a separate pid. It is that it is part of the controlling process group.

If you get it into either the background, or get the shutdown to do things
in the background. This user was using "shutdown -h +5 <message>".

That means the process remains part of the tree, and with a delay in the shutdown.

This gives cron control over the job - when cron recieves the shutdown (I believe before the +5 completes) the shutdown could get aborted.

Without the delay, I think the actual shutdown is controlled by init only.
I will admit, I'm not absolutely certain. shutdown used to be a script with easy visibility over how it is working, and the ramifications of various environments easy work out.
Reply With Quote
Reply

Tags
cron, shutdown, weekend

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop internet on weekend . mypass604 Servers & Networking 1 6th February 2011 11:37 AM
Weekend Music BugRocks1 Wibble 0 20th June 2010 09:10 AM
Thanksgiving Weekend Drive Dan Wibble 5 14th January 2009 11:05 PM
Weekend project? schwim Wibble 19 25th August 2007 11:33 AM
Ugly weekend upgrading to FC4 erasmix EOL (End Of Life) Versions 4 28th June 2005 04:50 AM


Current GMT-time: 13:56 (Wednesday, 22-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat