HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue on Cron

 
Vidhya B
Frequent Advisor

Issue on Cron

Hi,

I need a script to be executed every second. So, I have scheduled that in cron. But I found its not getting executed.

This is my crontab entry.

* * * * * sh /home/glance/Check_Perform_Action.sh

The content of Check_Perform_Action.sh
is below.
if [ -e /home/glance/Perform_Action.sh ]
then
./Perform_Action.sh
sleep 10
rm -rf Perform_Action.sh
fi

When the Perform_Action.sh executed, a file has to be generated. Thats the content of that file.

Kindly help.

Thanks in Advance!!!
6 REPLIES
Mel Burslan
Honored Contributor

Re: Issue on Cron

first thing : cron is granular to 1 minute not at seconds level. Your cron entry tells it to run every minute not second.

second thing: if some other script/program is not generating the Perform_Action.sh script, and you are deleting it on the line just before the last, how do you expect it to run again, 10 seconds later ?
________________________________
UNIX because I majored in cryptology...
Vidhya B
Frequent Advisor

Re: Issue on Cron

Hi,

I need to run the Perform_Action.sh Script when it is found in the specified path.
So, I need a script to check whether the Perform_Action.sh script is present or not. If it exist, then it should run the Perform_Action.sh.

Thanks!!
Mel Burslan
Honored Contributor

Re: Issue on Cron

help in what then.

you cron script check_perform_action, runs every minute,

if the script perform_action exists

runs it, waits for 10 seconds after run is complete and then deletes it

then exits

if the script perform_action does not exist at the time check_perform_action, you are out of luck. check_perform_action exits without doing anything

I think you want something like that as your check_perform_action.sh script

s=1
while [ $s -le 58 ]
do

if [ -e /home/glance/Perform_Action.sh ]
then
./Perform_Action.sh
sleep 10
rm -rf Perform_Action.sh
exit 0
fi

(( s=$s+1 ))
sleep 1
done


This is not a bullet proof script but it runs in a way close to how you want it to run
________________________________
UNIX because I majored in cryptology...
RickT_1
Valued Contributor

Re: Issue on Cron

If you want it to run that often, why don't you just let it run forever and put a sleep command in to give it a little time between checks. That way you don't have to mess with cron.

Rick
Vidhya B
Frequent Advisor

Re: Issue on Cron

Hi all,

When I run the Check_Perform_Action.sh manually, I am not facing any issue. The Perform_Action.sh is executed properly and I am getting the desired output. Only when I schedule it through cron, I am facing issue.

This is my Perform_Action.sh:

i=`hostname`
bdf >> /home/glance/Action_Performed_$i

Thanks!!!
Mel Burslan
Honored Contributor

Re: Issue on Cron

What issue ??
I explained how your script works.
you have a wrong assumption:
your Check script thru cron will only run once every minute and if yout action script is there it will run it once and exit. If it is not there, it will exit without doing anything.

under the circumstances, what issue are you talking about ? you want something from this script but you are not telling it how to do it. Do you know the famous saying "Computers do what you TELL them to do, NOT what you WANT them to do" ? It is famous for a reason.

I gave you a rough example how to accomplish it above or you can do as Rick says and leave the cron stuff aside and leave the script running all the time with 1 second sleep intervals.
________________________________
UNIX because I majored in cryptology...