How do I get the crontab to run a shellscript?

1

I have a .sh and I'm having difficulty running it in crontab every minute

Example I have my .sh file /var/www/exec/checarserver.sh it has permissions.

add it to crontab

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

It does not work already I tried too

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

also does not work.

    
asked by anonymous 04.04.2016 / 16:12

1 answer

2

Well try the command sh because I believe it is better for this purpose than bash . To make sure your path is exactly that, use the command which to find (or if you want more info 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 ... did you add the execution command in the first line of your '.sh' file? Because some servers do not run the file without this.

#!/bin/bash

Are you using absolute paths within your '.sh' file? Because crontab does not know how to work with relative paths and did you actually give permission with chmod 777 /var/www/html/exec/checarservidor.sh or chmod +x /var/www/html/exec/checarservidor.sh to your file?

    
04.04.2016 / 16:32