LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Shell scripting cron jon (http://www.linuxquestions.org/questions/programming-9/shell-scripting-cron-jon-900403/)

elieobeid7 08-31-2011 09:45 AM

Shell scripting cron jon
 
I have a radio and would like to run a specific playlist on fridays.

so on fridays 8 pm i would like to execute this command

cd /home/shoutcast/shoutcast/sc_trans/killall -9 ./sc_trans./sc_trans oldies.conf &

then on 9 pm i would like to execute this one

cd /home/shoutcast/shoutcast/sc_trans/killall -9 ./sc_trans./sc_trans &

this changes the playlist to be played on shoutcast, how to schedule these commands, I'm on centos 5

tronayne 08-31-2011 10:23 AM

You would use the crontab utility to set both up:
Code:

crontab -e
is how you do that (as "you"). The -e "edit crontab for user."

Now, what the heck do you do, eh?

If you look at the manual page for crontab there are examples that may prove useful. What you want to do is execute a command at 20 hours on Friday then execute another command at 21 hours on Friday which would look something like this
Code:

0 20 * * fri command
0 21 * * fri command

Now, in the above, command can be a shell program (rather than the long lines you have above); what you could do is save your first command line as a shell program named, oh, say, startit and that other as, what the heck, stopit and that might make things easier for you to keep track of (and if you ever have to edit either one...).

The fields in crontab are
Code:

MIN HOUR DAY MONTH DAY_OF_WEEK Command
Minutes are 0-59, hours are 0-23, Day is the day of the month, Day of the week is the three-character abbreviation, and Command is what to execute. Be sure to peruse the manual page for more details and examples.

Note that you really do need to look at the manual page for your distribution -- crontab varies from system-to-system and may not be identical on all.

Hope this helps some.

elieobeid7 08-31-2011 10:31 AM

thank you :D

elieobeid7 08-31-2011 10:57 AM

sir just one more thing, how to save and ext contab-e

i tried every method listed here and none works

http://www.computing.net/answers/sol...tab-e/313.html

i have a centos 5, vi come by default with yum and i installed nano

chrism01 08-31-2011 10:02 PM

crontab -e invokes the default editor in $EDITOR in your env; usually vi/vim.
The editor creates a temp file copy for you to edit and puts you in there.
When you exit-with-save the editor normally eg ':x' for vi/vim, crontab will collect the temp file and use it to overwrite the real crontab file. It also notifies the cron dameon.
For the paranoid, create a test user and experiment.


All times are GMT -5. The time now is 03:24 PM.