LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-19-2016, 07:19 PM   #16
Dickster2
LQ Newbie
 
Registered: Jul 2016
Location: Mountain View, CA
Posts: 23
Blog Entries: 1

Rep: Reputation: Disabled

Quote:
Originally Posted by NotionCommotion View Post
Hi,

vi /etc/init.d/15_second_cron
Code:
#!/bin/bash
# /etc/init.d/15_second_cron

### BEGIN INIT INFO
# Provides:          15_second_cron
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: PHP Loop
# Description:       Initiate a given PHP file which updates the database every 15 seconds
### END INIT INFO

while true
do
 /usr/bin/php /var/www/cron.php &
 sleep 15
done
exit 0
Code:
# Make script executable
chmod +x /etc/init.d/15_second_cron

/etc/init.d/15_second_cron start
chkconfig --levels 235 15_second_cron on
You originally stated: "Currently, I can have multiple instances all running at once and updating the database causing havoc." If that's true, then you really only want one updating job running at any given time. So, after your "sleep 15", you could test if your previous instance of /usr/bin/php is still running. Insert code such as the following after "sleep 15" and before "done". This may solve your problem.

Code:
  myjob=$(ps -ax | grep '[/]usr/bin/php')
  while [ -n "$myjob" ]; do
    sleep 5
    myjob=$(ps -ax | grep '[/]usr/bin/php')
  done

Last edited by Dickster2; 10-19-2016 at 07:36 PM.
 
Old 01-03-2017, 02:26 PM   #17
cesarbergara
Member
 
Registered: Feb 2012
Location: Buenos Aires, Argentina
Distribution: Debian, Suse, Mandrake,
Posts: 73

Rep: Reputation: Disabled
Hi. Why you dont try to execute like this in crontab or init:


echo Hello
sleep 15
exec PATH/BASH_SCRIPT_NAME &


When your script finish wait 15 seconds, and then executed himself like a new job, and finishing current job.

Have a nice day.
 
Old 01-03-2017, 05:08 PM   #18
Dickster2
LQ Newbie
 
Registered: Jul 2016
Location: Mountain View, CA
Posts: 23
Blog Entries: 1

Rep: Reputation: Disabled
Read the Description in the script. I believe the user's problem is that s/he can't force the "currently executing job" to stop until it's really done. Databases are very tricky, and don't like being left half-updated.
 
Old 01-26-2017, 04:06 PM   #19
cesarbergara
Member
 
Registered: Feb 2012
Location: Buenos Aires, Argentina
Distribution: Debian, Suse, Mandrake,
Posts: 73

Rep: Reputation: Disabled
Hi. I said 'use sleep' to do your job, in the meantime up to find or solve script problem (excuse my english).
I don't know about database, but in my experience like user, when you access a data on the database, the system 'block' data when you access it and could need to change it. But if you only 'see' it, you can access, but can't change (copy, move o change files).

Have a nice day.
 
Old 01-26-2017, 05:01 PM   #20
Dickster2
LQ Newbie
 
Registered: Jul 2016
Location: Mountain View, CA
Posts: 23
Blog Entries: 1

Rep: Reputation: Disabled
cesarbergara, I've been dealing with database processing since 1972. I can tell you that database processing can take varying amounts of time, depending upon many factors, such as index updating. Having a fixed amount of time may lead to timing conflicts. Note that the bash script is always running, in a while-loop. It spawns a php job, which supposedly performed a database update, but another simultaneous job would cause a conflict. That's why I suggested adding another loop to test for completion of a prior job, before submitting another.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job script creating corrupt archive roach7711x Linux - Server 2 04-08-2009 05:01 AM
I can execute shell script from CLI but failed to do via cron UltraSoul Linux - Software 2 06-24-2008 11:10 PM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM
How to set up cron job to execute bash script lgmqy2000 Linux - General 4 11-22-2006 05:29 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 12:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration