0

I am trying to run a simple script through a crontab task but nothing is run. Any error is displayed. I make the following:

  • Create a simple script with the following code: echo "Hola mundo". I name the script hola.sh.

  • I want this script to be run using crontab. I type crontab -e and I copy the following line, where tmp is a directory created in my diectory, /home/alex:

    15 * * * * /tmp/cat hola.sh
    

When minut 15 arrive, nothing is displayed. The logs are not indicating errors:

enter image description here

What I am doing wrong?

Thanks

1

2 Answers 2

1

You may or may not have tmp in your home, but your 2nd crontab entry is referencing /tmp, which is under the root directory /, not under /home/alex.

You also seem to just have separated the directory entry from the command cat with a space, that isn't going to work.

As for no error ... check your mail. The output of commands in crontab doesn't end up in the logs.

Try the following:

15 * * * * /bin/cat /home/alex/hola.sh

That, however, also won't produce any visible output by default; you'll need to check it in your local mail.

2
  • Thanks for the answer. I tried to change what you point me and it does not run. I changed the crontab code: 58 * * * * tmp/cat hola.sh and it did not run.
    – axmug
    Commented Apr 28 at 19:00
  • @axmug - no, that won't work, either. Try it tmp/cat hola.sh on the command line and you'll get an error message, too. I'll add an invocation that should work to my answer.
    – tink
    Commented Apr 28 at 20:09
0

The script location was not clearly specified. If the tmp directory you named is really a subfolder of /home/alex then you can move the script in it and then it may be invoked using its absolute path:

/home/alex/tmp/hola.sh

please check if this script is executable by your user, i.e. if the ls -l command returns a "x" as 4th character

ls -l /home/alex/tmp/hola.sh
-rwxr-x--- alex alex 220 2021-04-26 11:55:21 /home/alex/tmp/hola.sh

if not, you can fix it with chmod u+x /home/alex/tmp/hola.sh then the involved entry in crontab should be similar to

15 * * * * /home/alex/tmp/hola.sh

the cron job output is usually sent via email, but the error in the screenshot you posted also reports that the email system is now working ("no MTA installed..."): you can then collect the output (both stdout and sterr) using the normal redirection:

15 * * * * /home/alex/tmp/hola.sh >/home/alex/tmp/output.txt 2>&1
1
  • I have tried everything you point it and it does not run yet. I don't know what to do
    – axmug
    Commented Apr 28 at 23:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .