Issues getting crontab to work.

Firs with the shebang #!/bin/bash you already defined this is a Bash script. Next step is to create the file executable to run it without the command bash in from of it:

chmod +x /home/lskidson/tests/script.sh 

In general the command sudo is not applicable within crontab. If you need to run Cronjob by root you can use the root's crontab, that can be achieved by the command sudo crontab -e.

Now we can go to the Crontab's question. Where you expect to receive the message "I work"? There are few cases.

1. If the executable file generates an output file, or just modifies some things, the Cron job should be:

* * * * * /home/lskidson/tests/script.sh 

2. If the program doesn't write any output file and just generates some data within the stdout (as it is in your case), you should redirect it to a file to see it into an appropriate place (this part 2>&1 redirects and the error messages to stdout):

* * * * * /home/lskidson/tests/script.sh >> /home/lskidson/tests/script.sh.log 2>&1

3. While the stdout isn't redirected, Cron will sending local mails to the user (if your local mail is setup properly), unless this is overridden by setting the variable MAILTO in crontab:

MAILTO="[email protected]"
* * * * * /home/lskidson/tests/script.sh

References:

  • How to detect error in cron jobs
  • How do I make cron create cron.log?

How do you know it never runs? It is not going to echo to your terminal. First drop the sudo...that should never be in a cronjob. A crontab for root runs as root, the crontab for a user runs as the user, place your script accordingly.

Pipe your output to file like so

echo "I work" > /path/to/some/file.txt

or

* * * * * /home/lskidson/tests/script.sh > /path/to/some/file.txt

Use > to overwrite the file, >> to append to it.