-3

I have a shell script, named test.sh.

#! /bin/bash
mysql -u root -p <<dbEmployee1
use dbEmployee1;
UPDATE EMPLOYEE SET EMPLOYEE_NAME = 'Cyndi' WHERE EMPLOYEE_ID ='1'; 
SELECT * from EMPLOYEE;
dbEmployee1

mysql -u root -p <<dbBooks
use dbBooks;
SELECT * FROM Author;
dbBooks

following this tutorial what I want to do is have my script run every 10 seconds, but instead I get below results.

seng@wseng:/$ */10 * * * * /home/seng/Desktop/test.sh
bash: proc/10: Is a directory

What have I missed or done wrong here?

Edit (After execute crontab -e)

# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
* * * * * cd /home/seng/Desktop/test.sh
Memor-X
  • 2,870
  • 6
  • 33
  • 57
John Joe
  • 12,412
  • 16
  • 70
  • 135

1 Answers1

2

Cron only allows minimum of 1 minute. So to schedule for every 10 second, all you could do is to call the script in another script that runs every 10 seconds. This may not be the correct solution but would serve your purpose.

Here is a simple script that would do the job:

#!/bin/sh

while true
do

sh test.sh
sleep 10 

done

Also, keep in mind the time test.sh takes to execute. You can accordingly vary the sleep time in the script.

If You want to run it in one minute then here is the process.

  • You need to be sure the user who would have the permission to run the script should be the present logged in user.

  • Enter crontab -e on the command line (will open an editor). Enter the following

    * * * * * /absolute/path/to/the/script

Now close the editor by first pressing ESC key and :wq followed by ENTER

Explanation:

 .---------------- minute (0 - 59)
 |  .------------- hour (0 - 23)
 |  |  .---------- day of month (1 - 31)
 |  |  |  .------- month (1 - 12)
 |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)
 |  |  |  |  |
*  *  *  *  * command to be executed

Each astrick value is mentioned and can be put accordingly.

For e.g :

To run something every minute :

* * * * * command to be executed

To run something at midnight everyday :

0 0 * * * command to be executed

You can list all your cronjobs by executing crontab -l command and remove any by crontab -r.

Just make sure for two more things, to restart cron daemon (service crond restart) everytime the file is changed and permission level on the script you would be executing with it (check /var/mail/<user> for logs).

Ashish K
  • 905
  • 10
  • 27
  • This is a partial answer at best. The OP has a number of other problems, some of them unrelated. – tripleee Mar 20 '17 at 12:35
  • Ya, as I already mentioned this may be not the correct solution but would suffice the requirement. However you are correct as in the shell running the script should be up and running all the time. – Ashish K Mar 20 '17 at 12:44
  • If I want it to run one minute, how should it be ? – John Joe Mar 20 '17 at 14:42
  • 1
    Please go through the edit. I have described the process with explanation :) – Ashish K Mar 20 '17 at 20:04