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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
10-19-2016, 06:19 PM
|
#16
|
LQ Newbie
Registered: Jul 2016
Location: Mountain View, CA
Posts: 23
Rep:
|
Quote:
Originally Posted by NotionCommotion
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 06:36 PM.
|
|
|
01-03-2017, 01:26 PM
|
#17
|
Member
Registered: Feb 2012
Location: Buenos Aires, Argentina
Distribution: Debian, Suse, Mandrake,
Posts: 92
Rep:
|
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.
|
|
|
01-03-2017, 04:08 PM
|
#18
|
LQ Newbie
Registered: Jul 2016
Location: Mountain View, CA
Posts: 23
Rep:
|
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.
|
|
|
01-26-2017, 03:06 PM
|
#19
|
Member
Registered: Feb 2012
Location: Buenos Aires, Argentina
Distribution: Debian, Suse, Mandrake,
Posts: 92
Rep:
|
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.
|
|
|
01-26-2017, 04:01 PM
|
#20
|
LQ Newbie
Registered: Jul 2016
Location: Mountain View, CA
Posts: 23
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 01:38 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|