0

I have a .sh script that I've put in crontab with this command:

0 * * * * /root/Linux/lansare.sh

It doesn't run even though I made the script an executable. I checked it and it has x. I tried before the script to write : #!/bin/sh but it still doesn`t run

If I run it manually like ./lansare.sh from the folder it works.

Can you please help me make it work from crontab ?

Thanks

  • 1
    Did you add that line to root's crontab or another user's? – schaiba Sep 30 '19 at 8:37
  • see what cron logs when it tries to run it. depends on the distribution but there's probably something in /var/log, try e.g. grep -ie cron /var/log/*` – ilkkachu Sep 30 '19 at 8:54
  • What is in your script? how did you edited your crontab? and what is your current user? – Rasool Ziafaty Sep 30 '19 at 9:16
  • Did the user who owns this crontab get any error messages emailed to them by the cron daemon? – Kusalananda Sep 30 '19 at 9:54
0

put this in your crontab

0 * * * * /root/Linux/lansare.sh >> /root/Linux/lansare.log 2>&1

and then read /root/Linux/lansare.log

This way, you'll get to see both the output steams (Stdout and Stderror) and you'll know what's wrong in the script.

| improve this answer | |
0

There are 2 different ways to put it in crontab:

  1. Did you run crontab -e which the starts an editor where you typed 0 * * * * /root/Linux/lansare.sh? If so, then make sure you run the crontab -e command as root because you have your script in /root where normal user do not have permissions.

  2. Did you put it in /etc/crontab or in a file in /etc/cron.d/? If so, then you have include the username you want to use to run the script (in your case root) in the line. Like this:

    0 * * * * root /root/Linux/lansare.sh
    #         ^^^^----[here]
    
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.