CRONTAB: control operator in command

bsus

Well-Known Member


Messages: 299

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

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,370
Messages: 29,907

Put some parentheses around them.

Code:
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

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 2,786
Messages: 11,279

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.
 
OP
OP
B

bsus

Well-Known Member


Messages: 299

@DutchDaemon
without them the last command isn't executed

@SirDice
Thank you, will try this later on
 

DutchDaemon

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 2,786
Messages: 11,279

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:

Code:
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.
 

DutchDaemon

Administrator
Staff member
Administrator
Moderator
Developer

Reaction score: 2,786
Messages: 11,279

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