M HYPE SPLASH
// general

Running two commands in crontab

By Emily Wilson

I have this line in my crontab file

*/1 * * * * espeak 'foo' && espeak 'bar'

But only half of it, first command gets executed every minute.

While when I write this in the terminal it works like a charm.

Is there a different way to execute 2 commands in the same line in the crontab file ?

1

2 Answers

&& is interpreted by bash as one of the operators that separate pipelines in a command line. If you call those commands from bash both should run:

*/1 * * * * bash -c 'espeak "foo" && espeak "bar"'
2

Using && in crontab is correct.

If the second command is not executed, it means that the first command does not return successfully. You may then want to use espeak 'foo'; espeak 'bar' (so the second command is executed whatever the first one returns), but that does not tell you why the first command does not return successfully.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy