News Register Control Panel Private Messages Members List Team Search News Posts About Us

Linux Advisory » Q & A - Discussions » Programming & Coding » Checkif script running, if not, start it. » Hello Guest [login|register]
Last Post | First Unread Post Print Page | Recommend to Friend | Add Thread to Favorites
Post New Thread Post Reply
Author
Post « Previous Thread | Next Thread »
forefront forefront is a Male
Newbie


Registration Date: 06-23-2003
Posts: 5
Location: Long Beach, CA
Linux Distro: LindowsOS

Rate Member

Level: 7 [?]
Experience Points: 390
Next Level: 443
53 point(s) of experience needed for next level

OFFLINE

Check if script running ... if not, start it. Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

I'm trying to do this in sh:

I want to set up a cron job that periodically will run a check.sh script to see if a PHP script called proxy.php is running on the webserver. If it is, do nothing ... if it's not, start it up. I'm lost as to how to go about determing if the script is running. Any help you can provide is really appreciated by this newbie!

This post has been edited 1 time(s), it was last edited by forefront on 06-23-2003 at 22:09.

06-23-2003 22:08 Send an Email to forefront Search for Posts by forefront Add forefront to your Buddy List
Heather Heather is a Female
Lord




Registration Date: 05-21-2003
Posts: 390
Location: Lost City of Zen.
Linux Distro: I'm OS neutral.

Rating:
8 Votes - Average Rating: 4.00

Level: 22 [?]
Experience Points: 43.323
Next Level: 49.025
5.702 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Hmm, I can't say that I've ever done something like that before. I'll look into it.

Why does it need to be a cronjob?



Utinam logica falsa tuam philosophiam totam suffodiant

This post has been edited 1 time(s), it was last edited by Heather on 06-24-2003 at 00:25.

06-24-2003 00:25 Send an Email to Heather Search for Posts by Heather Add Heather to your Buddy List
forefront forefront is a Male
Newbie


Registration Date: 06-23-2003
Posts: 5
Location: Long Beach, CA
Linux Distro: LindowsOS

Rate Member

Level: 7 [?]
Experience Points: 390
Next Level: 443
53 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

The cron will do the periodic check running the basic script. If the script has no argument (i.e. start, stop or restart), then it just checks to see if the program is running. If not, it starts it.

The proxy.php is an anti-spam system that sits between the POP3 email client and the standard POP3 service.

The software works, but is still being debugged and further tested. Sometimes it stops and we're still trying to find out why, but if it stops, users cannot get mail without reconfiguring their email clients.

06-24-2003 00:38 Send an Email to forefront Search for Posts by forefront Add forefront to your Buddy List
Telos Telos is a Male
Super Moderator


Registration Date: 06-04-2003
Posts: 118
Location: Finland
Linux Distro: hmm....

Rating:
2 Votes - Average Rating: 5.50

Level: 17 [?]
Experience Points: 11.514
Next Level: 13.278
1.764 point(s) of experience needed for next level

ONLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

I think you have to make a script to do the functionality first and then just call that script in cronjob. Sorry, but I can't help you with the script but I think that's how you should do it.



06-24-2003 07:25 Send an Email to Telos Homepage of Telos Search for Posts by Telos Add Telos to your Buddy List Add Telos to your Contact List AIM Screenname: dreamimpactcom
Heather Heather is a Female
Lord




Registration Date: 05-21-2003
Posts: 390
Location: Lost City of Zen.
Linux Distro: I'm OS neutral.

Rating:
8 Votes - Average Rating: 4.00

Level: 22 [?]
Experience Points: 43.323
Next Level: 49.025
5.702 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Forefront...cron jobs don't do anything but run commands at pre-assigned times. What you first need to do is make a script that does what you need it to do. It can be cgi, sh, or anything else. After that is done and it works, then you set it up to be run in a cron job.



Utinam logica falsa tuam philosophiam totam suffodiant

06-24-2003 15:44 Send an Email to Heather Search for Posts by Heather Add Heather to your Buddy List
forefront forefront is a Male
Newbie


Registration Date: 06-23-2003
Posts: 5
Location: Long Beach, CA
Linux Distro: LindowsOS

Rate Member

Level: 7 [?]
Experience Points: 390
Next Level: 443
53 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Uh ... I guess I wasn't very clear. I know I need to write a script and I'm using sh or maybe bash. I know how to search to see if a script or program is running, but I don't know what happens when it's not running, how to parse the result, detect the response and have my script respond appropriately. I've searched high and low on the Net for anything similar, but so far I've come up blank.

This post has been edited 1 time(s), it was last edited by forefront on 06-24-2003 at 20:19.

06-24-2003 20:18 Send an Email to forefront Search for Posts by forefront Add forefront to your Buddy List
Heather Heather is a Female
Lord




Registration Date: 05-21-2003
Posts: 390
Location: Lost City of Zen.
Linux Distro: I'm OS neutral.

Rating:
8 Votes - Average Rating: 4.00

Level: 22 [?]
Experience Points: 43.323
Next Level: 49.025
5.702 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

quote:
Originally posted by forefront
Uh ... I guess I wasn't very clear. I know I need to write a script and I'm using sh or maybe bash. I know how to search to see if a script or program is running, but I don't know what happens when it's not running, how to parse the result, detect the response and have my script respond appropriately. I've searched high and low on the Net for anything similar, but so far I've come up blank.

Well, parsing a script's progress...I know how to make it print progress indictators into an ssh session...but I'm not 100% sure what you're asking.



Utinam logica falsa tuam philosophiam totam suffodiant

06-24-2003 21:23 Send an Email to Heather Search for Posts by Heather Add Heather to your Buddy List
forefront forefront is a Male
Newbie


Registration Date: 06-23-2003
Posts: 5
Location: Long Beach, CA
Linux Distro: LindowsOS

Rate Member

Level: 7 [?]
Experience Points: 390
Next Level: 443
53 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

When the script is run by NOT run by crontab, it will contain normally contain an argument of stop, start, or restart. When crontab runs it, those arguments will be missing, so the script logic will be to check to see if proxy.php is currently running and if it is, do nothing and quit ... otherwise do the 'start' function.

For example, here's the 'start' function:
start()
{
command="nohup proxy.php &"
exit 0
}

... and the 'stop' function:
stop()
{
command="ps -auxww | grep \"php\" | awk '{print $2}' | xargs kill -9"
exit 0
}

So, if I want to have a check function, I get this far:
check()
{
command="ps -auxww | grep \"php\"" | awk '{print $2}'
}
This returns the PID. If it is not running, it returns nothing. How do I detect nothing? Once I know how to do that, then I can start/exit or just exit. It gets easy then.

This post has been edited 3 time(s), it was last edited by forefront on 06-24-2003 at 23:49.

06-24-2003 23:42 Send an Email to forefront Search for Posts by forefront Add forefront to your Buddy List
Telos Telos is a Male
Super Moderator


Registration Date: 06-04-2003
Posts: 118
Location: Finland
Linux Distro: hmm....

Rating:
2 Votes - Average Rating: 5.50

Level: 17 [?]
Experience Points: 11.514
Next Level: 13.278
1.764 point(s) of experience needed for next level

ONLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

I don't know anything about the language you are using but I would imagine that if you want to detect nothing you have to detect if it is something else than the pid. I don't know if it works but that's the logic I would probably use.



06-25-2003 07:36 Send an Email to Telos Homepage of Telos Search for Posts by Telos Add Telos to your Buddy List Add Telos to your Contact List AIM Screenname: dreamimpactcom
forefront forefront is a Male
Newbie


Registration Date: 06-23-2003
Posts: 5
Location: Long Beach, CA
Linux Distro: LindowsOS

Rate Member

Level: 7 [?]
Experience Points: 390
Next Level: 443
53 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

I'm down to one basic problem to make this work:

How do I get the results of the "command=..." into a variable?

Once that's done, I can test to see if it's null or not.

06-25-2003 14:39 Send an Email to forefront Search for Posts by forefront Add forefront to your Buddy List
Post Reply:
Title (Optional):
Message:


Convert URLs: Automatically converts internet addresses into links by adding [url] and [/url] around them.
Email Notification: Notifies you by email every time there is a new post in this thread.
Deactivate smilies in this post.
Add Signature: Displays your signature in this post.


Tree Structure | Board Structure
Post New Thread Post Reply
Go to:


Powered by Burning Board 2.0.2 © 2001-2002 WoltLab GbR
English Translation by Satelk