Run Linux shell script in every few minutes/hours/monthly ...
Q: How can I run Linux shell script in every n minute/hours/monthly
A: By using while loop in script or 'CRON'
'CRON' is best Choice
Cron is a daemon found on most Unix/linux systems that runs scheduled commands at the specified intervals.
You add a script to the list by copying it to the folder of your choice:
cron.daily
cron.hourly
cron.monthly
cron.weekly
These folders are typically found in /etc
OR
Just type below command on consol and editor will open,
$crontab -e
In this there ia a line like
# * * * * * command
Remove # from the begining of The line and set like you want
for 10 minute
*/10 * * * * ./script
for 2 hours
0 */2 * * *
here ./script is may be linux command or a script.
By using this we can RUN Hadoop/Hive/PIG scripts on every Interval which we want.
=================xxxxxxxxxxxxxxxx============================
My Scripts
=============================================================
script.sh file in Home directory(/home/dinesh/script.sh)
#!/bin/bash
# My first script
mkdir mydir$(date +%S-%M-%H-%d-%m-%Y)
My crontab -e file looks like below, I want to run it in every 5 minute.
#some other
#content
#
*/5 * * * * ./script.sh
#
#some other
#content
---------------------
We don't need to start it, it will automatically start running.
If we need to stop it then again type "crontab -e"
and comment 4th line(which contains * *) as you can see in above example.
Thats it.
A: By using while loop in script or 'CRON'
'CRON' is best Choice
Cron is a daemon found on most Unix/linux systems that runs scheduled commands at the specified intervals.
You add a script to the list by copying it to the folder of your choice:
cron.daily
cron.hourly
cron.monthly
cron.weekly
These folders are typically found in /etc
OR
Just type below command on consol and editor will open,
$crontab -e
In this there ia a line like
# * * * * * command
Remove # from the begining of The line and set like you want
for 10 minute
*/10 * * * * ./script
for 2 hours
0 */2 * * *
here ./script is may be linux command or a script.
By using this we can RUN Hadoop/Hive/PIG scripts on every Interval which we want.
=================xxxxxxxxxxxxxxxx============================
My Scripts
=============================================================
script.sh file in Home directory(/home/dinesh/script.sh)
#!/bin/bash
# My first script
mkdir mydir$(date +%S-%M-%H-%d-%m-%Y)
My crontab -e file looks like below, I want to run it in every 5 minute.
#some other
#content
#
*/5 * * * * ./script.sh
#
#some other
#content
---------------------
We don't need to start it, it will automatically start running.
If we need to stop it then again type "crontab -e"
and comment 4th line(which contains * *) as you can see in above example.
Thats it.
Comments
Post a Comment