Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-31-2011, 09:45 AM   #1
LQ Newbie
Registered: Jul 2011
Posts: 24

Rep: Reputation: Disabled
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
Old 08-31-2011, 10:23 AM   #2
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,280

Rep: Reputation: 894Reputation: 894Reputation: 894Reputation: 894Reputation: 894Reputation: 894Reputation: 894
You would use the crontab utility to set both up:
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
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
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.
1 members found this post helpful.
Old 08-31-2011, 10:31 AM   #3
LQ Newbie
Registered: Jul 2011
Posts: 24

Original Poster
Rep: Reputation: Disabled
thank you
Old 08-31-2011, 10:57 AM   #4
LQ Newbie
Registered: Jul 2011
Posts: 24

Original Poster
Rep: Reputation: Disabled
sir just one more thing, how to save and ext contab-e

i tried every method listed here and none works

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

Last edited by elieobeid7; 08-31-2011 at 10:59 AM.
Old 08-31-2011, 10:02 PM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.7, Centos 5.10
Posts: 17,013

Rep: Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245Reputation: 2245
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.


shell script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
Questions about shell scripting and cron jobs carlito11973 Programming 2 10-06-2006 11:34 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM

All times are GMT -5. The time now is 05:18 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration