How do I make crontab run a shellscript?

Asked

Viewed 1,809 times

1

Guys I have a . sh and I’m having difficulty making it run on crontab every minute

Example I have my file . sh /var/www/exec/checarservidor.sh it is with due permissions.

add it to crontab

* * * * *  /var/www/html/exec/checarservidor.sh | sendmail -s "crontab rodado" [email protected]

It doesn’t work I tried too

* * * * *  /bin/bash /var/www/html/exec/checarservidor.sh | sendmail -s "crontab rodado" [email protected]

also doesn’t work.

1 answer

2


Well try the command sh because I believe it is better for that purpose than the bash. To make sure your way is exactly this use the command which to discover (or if you want more Infos use whereis):

which sh
whereis sh

Getting more or less like this at the end:

* * * * * /bin/sh /var/www/html/exec/checarservidor.sh | sendmail -s "crontab rodado" [email protected]

Other details are ... have you added in the first line of your '.sh' file the run command? Because some servers do not run the file without it.

#!/bin/bash

Are you using absolute paths within your '.sh' file? For the crontab does not know how to work with relative paths and finally really gave permission with chmod 777 /var/www/html/exec/checarservidor.sh or chmod +x /var/www/html/exec/checarservidor.sh for your file?

  • 1

    It worked!! Thank you! s2s2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.