954,249 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

can cron detect php script

Hi
I've writen a server is PHP that i want to run every min.
so i can do something like in cron

*/1 * * * * lynx -dump http://www.somedomain.com/myserver.php


But i want to make sure there only 1 running.
The web tells met to check for an prosesid but i running PHP as an apache module so ther is no prosesid.
Does any one have any idears?

Thanks

p.s runing redhat el5

pzuurveen
Posting Whiz in Training
229 posts since Sep 2006
Reputation Points: 32
Solved Threads: 47
 

Write a bash script to run that line of code. Something similar to this:

#!/bin/bash

PID_GREP=`ps aux | grep http://www.somedomain.com/myserver.php | grep -v grep`
PID_COUNT=`echo "$PID_GREP" | awk '/myserver.php/ { n++ }; END { print n+0 }'`
if [ ! $PID_COUNT ]
then
lynx -dump http://www.somedomain.com/myserver.php
fi

Rick Bross

rbross
Newbie Poster
12 posts since Jan 2011
Reputation Points: 15
Solved Threads: 1
 

Thanks f
But it doesn't work
if i do

ps aux


i get alot of apache 4365 0.0 0.7 386096 45168 ? S JAN25 1:26 /usr/sbin/httpd


but no referens to what website they serves

pzuurveen
Posting Whiz in Training
229 posts since Sep 2006
Reputation Points: 32
Solved Threads: 47
 

My fault, as I only search for part of your string. You can search for the entire command string.

If you respond, please cut and paste your script. Every tick mark, punctuation, and space is important in a shell script.

Also, another mistake is the line should be:

if [ $PID_COUNT == 0 ]

I didn't actually run the script. It was intended as a baseline for you.

rbross
Newbie Poster
12 posts since Jan 2011
Reputation Points: 15
Solved Threads: 1
 

Thank that helpt a lot

ure code was fare les buggy then my first test about it
sorry for that

think it works now

FYI

- wasn't that sure about lynx -dump option so now using curl
- didn't get awk to read $PID_GREP so had to put it all in one line
- awk don't like . (dot)

#!/bin/bash
PID_COUNT=`ps aux |grep curl |grep -v grep |awk '/layer/tweetserver { n++ }; END {print n+0}'`
if [ $PID_COUNT == 0 ]
then
curl http://www.openeindhoven.nl/layer/tweetsever.php
fi]
pzuurveen
Posting Whiz in Training
229 posts since Sep 2006
Reputation Points: 32
Solved Threads: 47
 

Glad it worked out for.

RB

http://www.silverspore.com

rbross
Newbie Poster
12 posts since Jan 2011
Reputation Points: 15
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: