# CRONTAB: control operator in command



## bsus (Mar 28, 2012)

Hi,

I want to execute a chain of commands via crontab:
`# /usr/local/sbin/zfSnap -a 30d storage/home && halt -p`

Right now I only execute a script which holds the chain but I would prefer to have the command directly in the crontab.


How do I do this?

Best Regards,
bsus


----------



## SirDice (Mar 28, 2012)

Put some parentheses around them.


```
root@vps-2417-1:~#crontab -l
# minute        hour    monthday        month   weekday         command
0               *       *               *       *               (cd /usr/local/www/awstats/cgi-bin && /usr/bin/perl ./awstats.pl --config=example.com)
```


----------



## DutchDaemon (Mar 28, 2012)

The parentheses aren't needed, unless you want to background the whole thing with & or send the output of the entire chain to a single file or /dev/null.


----------



## bsus (Mar 28, 2012)

@DutchDaemon
without them the last command isn't executed

@SirDice
Thank you, will try this later on


----------



## DutchDaemon (Mar 28, 2012)

I have numerous && concatenations in my cron jobs, without parentheses, and they always run to full completion. So I wouldn't know what causes this problem. One example:


```
5 0 1 * *	cd /usr/local/share/GeoIP && /usr/bin/fetch http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz && /usr/bin/gunzip -f GeoIP.dat.gz
0 * * * *	/usr/sbin/chown -R www:user /usr/local/www/wordpress && /bin/chmod -R u+rw,g+rw,o+r /usr/local/www/wordpress
```

Never fail.


----------



## bsus (Mar 28, 2012)

Have you defined bash as shell?


----------



## DutchDaemon (Mar 28, 2012)

No, cron is running as the default sh. Tested using an [cmd=]echo $SHELL[/cmd] in the crontab.


----------

