How To Run A Shell Script Again And Again Having X Interval Of Time?
Posted
by
Muhammad Hassan
on Ask Ubuntu
See other posts from Ask Ubuntu
or by Muhammad Hassan
Published on 2014-08-19T08:07:14Z
Indexed on
2014/08/19
16:30 UTC
Read the original article
Hit count: 449
I have a shell script in my Ubuntu Server 14.04 LTS at ./ShellScript.sh
. I setup /etc/rc.local
to run the shell script after boot but before login using below code.
Run this: sudo nano /etc/rc.local
then add following and save.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#!/bin/bash
./ShellScript.sh
exit 0
Now I want to run/execute this shell script again and again having 15min of time interval between every run after boot but before login. So Can I do it?
Update 1:)
When I run crontab -e
then I got the following. Now What to do?
no crontab for root - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/ed
2. /bin/nano <---- easiest
3. /usr/bin/vim.basic
4. /usr/bin/vim.tiny
Choose 1-4 [2]:
After selecting 2
, I got crontab: "/usr/bin/sensible-editor" exited with status 2
UPDATE 2:)
Update ShellScript.sh
like below...
#!/bin/bash
# Testing ShellScript...
while true
do
echo "ShellScript Start Running..."
**********************************
All My Shell Script Codes/Script/Commands
**********************************
echo "ShellScript End Running..."
exit 0
sleep 900
done
Then Run this: sudo nano /etc/rc.local
then add following and save.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sh ./ShellScript.sh &
exit 0
© Ask Ubuntu or respective owner