Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a simple shell script as a cronjob

Tags:

People also ask

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .


I have a very simple shell script I need to run as a cronjob but I can't get even the test scripts to run. Here's and example script:

/home/myUser/scripts/test.sh

#!/bin/bash
touch file.txt

crontab:

* * * * * /home/myUser/scripts/test.sh

The script runs fine from the terminal but can't get it to run as a cronjob. So far I've tried these in crontab:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

* * * * * /bin/bash /home/myUser/scripts/test.sh

And this in the the script file:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/myUser/scripts

From what I've gathered the solution might be in the PATH variable but I can't figure out what it is since my understanding is very limited at this point. So my question is, how do I get my scripts to run as cronjobs?

EDIT: the file has rwx permissions for all users. This is just for testing purposes.

EDIT: cronjobs such as * * * * * touch /home/myUser/scripts/test.txt work but it wont run scripts.