0

I have a Script called "test.sh" in my Home Directory

I want to be able to run it in crontab.

I have added

* * * * * /home/tom/test.sh

to the crontab however it doesn't seem to be excecuting.

I can excecute ./test.sh fine normally in a Terminal Window.

Edit:

This is the content of my script "test.sh"

#!/bin/sh
gnome-terminal -- sh -c 'cd Server && ./start.sh'

It creates a new terminal window, changes directory to Server and runs another executable script.

I do not know if this has something to do with the script not working in Cron.

The error I get in /var/log/syslog is:

CRON[18694]: (tom) CMD (sh /home/tom/test.sh)
CRON[18693]: (CRON) info (No MTA installed, discarding output)
tdubz
  • 51

1 Answers1

0

First and foremost, the syntax for the execution times is demonstrated here. The CronTab can be confusing, but there are an abundance of guides out there to help.

Now, in your case you have:

* * * * * /home/tom/test.sh

Depending on how you edited your Crontab, this could be a permission issue. Using bash, I always did the following:

* * * * * sh /home/tom/test.sh

Which is the same as the following:

* * * * * /home/tom/test.sh

With the theory that test.sh has a somewhat similar structure:

#!/bin/bash

for i in */ .*/ ; do 
    echo -n $i": " ; 
    (find "$i" -type f | wc -l) ; 
done

The last thing to check is that the script is executable:

chmod +x /home/tom/test.sh

For me, I performed the following on my Crontab:

# Example Crontab command:
# * * * * * /home/mn/Documents/Scripts/counta.sh >> /home/mn/Documents/Scripts/test

This was able to successfully run and output the test file as required.