LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-04-2014, 09:36 AM   #1
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Rep: Reputation: Disabled
cron execution using command line


how to execute a cron via command line
i have a case statement in my script which when pressed 1 executes another script
when i execute my script it must execute my cron how can i do it
eg #script1

Code:
case $rental in
"car") ./car.sh;;
"van") ./van.sh;;
*) echo "Sorry, I can not gat a $rental for you";;
esac
when i execute
Code:
./script1.sh car
my cron should execute the script1.sh

Last edited by desiretolearn; 02-04-2014 at 01:20 PM.
 
Old 02-04-2014, 05:03 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
The beauty of cron (and the oft forgotten 'at') is they schedule and execute commands without interaction. So either you're not looking for cron or you should be using something else you can influence externally to trigger a decision like for example the existence of a file, a specific log line, etc, etc.
 
1 members found this post helpful.
Old 02-05-2014, 12:10 AM   #3
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
unSpawn
Quote:
if [ -z in $1 ]
then
rental ="no value"
elif [ -n in $1 ]
then
rental =$1
fi
case $rental in
"car") ./car.sh;;
"van") ./van.sh;;
*) echo "Sorry, I can not gat a $rental for you";;
esac
cant this be done in cron!!!!
suppose i execute
Quote:
./script1.sh car
then my cron should execute
Quote:
* * * * * /script1.sh
since i have command line to pass is there any specificc code or any suggestion!
i know there is an error in the cron can you help me out

Last edited by desiretolearn; 02-05-2014 at 12:26 AM.
 
Old 02-05-2014, 02:15 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531Reputation: 3531
I suppose you could have your script1.sh modify your crontab:
Code:
MYTMPFILE=`mktemp -p /tmp .crontab.XXXXXXXXXX` && {
 # Set new crontab entry:
 echo "* * * * * /path/to/script1.sh" > "${MYTMPFILE}";
 # Add old crontab entries:
 /usr/bin/crontab -u $LOGNAME -l >> "${MYTMPFILE}"; 
 # Read in new user crontab:
 /usr/bin/crontab -u $LOGNAME "${MYTMPFILE}"; 
 }; rm -f "${MYTMPFILE}"
 
1 members found this post helpful.
Old 02-05-2014, 02:27 AM   #5
desiretolearn
LQ Newbie
 
Registered: Jan 2014
Posts: 25

Original Poster
Rep: Reputation: Disabled
THIS CODE should be written in my script or in crontab??
sorry for this silly question upswan..
 
  


Reply


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
gawk works from command line but not from cron fantasygoat Linux - Server 3 10-25-2011 02:18 PM
command line execution vs clicking on the icon icecubeflower Linux - Newbie 2 04-19-2009 05:39 PM
cron execution and command access champak Programming 2 11-29-2007 06:50 AM
Works from command line but not from the cron WingnutOne Linux - General 8 11-08-2007 09:18 AM
btdownload*.py, works from Command Line, not from cron SkipHuffman Linux - Software 11 12-30-2005 03:55 PM


All times are GMT -5. The time now is 06:42 PM.

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