LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cron execution using command line (https://www.linuxquestions.org/questions/linux-newbie-8/cron-execution-using-command-line-4175493677/)

desiretolearn 02-04-2014 08:36 AM

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

unSpawn 02-04-2014 04:03 PM

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.

desiretolearn 02-04-2014 11:10 PM

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

unSpawn 02-05-2014 01:15 AM

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}"


desiretolearn 02-05-2014 01:27 AM

THIS CODE should be written in my script or in crontab??
sorry for this silly question upswan..

unSpawn 02-05-2014 12:46 PM

Not a silly question. In your script. Here's more help:

http://www.gnu.org/software/bash/man...ode/index.html
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html

BASH scripting guides:
http://mywiki.wooledge.org/BashGuide
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
# these are must reads so do read them!

Common questions / problems:
http://mywiki.wooledge.org/ParsingLs
http://mywiki.wooledge.orgDontReadLinesWithFor
http://mywiki.wooledge.org/UsingFind
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes

The Advanced BASH scripting guide:
http://www.tldp.org/LDP/abs/html/

Bourne shell (compatibility):
http://www.grymoire.com/Unix/Sh.html

Also see:
http://www.linuxquestions.org/questi...l-links-35334/
http://www.linuxquestions.org/questi...nd-line-32893/
http://www.linuxquestions.org/questi...ks-4175433508/


All times are GMT -5. The time now is 03:40 AM.