How to run a cron job to execute every minute

cronrhel

I am trying to create a directory having a timestamp in its in name in the /home directory. I have created the following cron job as the root user, but it's not running. What am I doing wrong?

Following is my cron job which I have created with root user privilege.

[root@bvdv-emmws01 home]# crontab -l
* * * * * /home/test.sh

Following are the contents of /home/test.sh.
Update: added full path for directory.

[root@bvdv-emmws01 home]# cat /home/test.sh 
#!/bin/bash
mkdir /home/test_$(date -d "today" +"%Y%m%d%H%M%S")

Permission of /home/test.sh:

[root@bvdv-emmws01 home]# ls -ltr /home/test.sh
-rwxrwxrwx 1 root root 58 Dec  2 12:58 /home/test.sh

I have updated the /etc/crontab file. That file now has the following contents:

[root@bvdv-emmws01 home]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

* * * * * root /home/test.sh

Status of crond daemon

[root@bvdv-emmws01 home]# service crond status
crond (pid  1910) is running...

Best Answer

A crontab created with crontab -e and listable with crontab -l should not have a user specified for the command. Your entry should read:

* * * * * /home/test.sh

Or alternatively put the line that you have in /etc/crontab instead.

From man 5 crontab (section EXAMPLE SYSTEM CRON FILE):

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

Note the last sentence.

Related Question