Şansal Birbaş
Şansal Birbaş

Reputation: 453

Run two commands in cron

I need to run a task every hour . I first change directory to the path where script is and then operate that script. So I try to use a cron job as :

59 * * * * cd /home/sansal/Scripts && sudo ./usbreset /dev/bus/usb/002/003  

I added that line to crontab. But I cant make sure if it is true. And I dont see any output in terminal about that.

Upvotes: 0

Views: 1804

Answers (2)

willemdh
willemdh

Reputation: 856

Using the full path is defintely better then first using cd. To get the result of the cronjob, you could just output to file like this:

59 * * * * /home/sansal/Scripts/usbreset /dev/bus/usb/002/003 &>> /home/sansal/usbreset.log

Upvotes: 1

Barmar
Barmar

Reputation: 780787

You can test if the script failed with ||

59 * * * * /home/sansal/Scripts/usbreset /dev/bus/usb/002/003 || echo "usbreset failed"

cron automatically sends email with any output of the command.

Upvotes: 1

Related Questions