Click to See Complete Forum and Search --> : Need help setting up cron script to keep dnetc running


milanuk
10-18-2001, 06:44 PM
Well, the subject pretty much covers it. I want a small shell (bash) script that runs from cron, say every half hour or hour, checks to see if user 'monte' has a dnetc session running, and if not, starts dnetc w/ the '--quiet' flag.

I've piddled around in the past w/ no success. I really don't even really remember what I tried back then (several months ago, at least), and I'm pretty much ignorant when it comes to shell programming. I'm not against learning, I just need some well directed kicks^h^h^h^h^h nudges in the right direction ;)

TIA,

Monte

Dark Ninja
10-18-2001, 07:05 PM
:: kicks milanuk a few times ::

There - now learn shell scripting.

I just started teaching it to myself (so, I can't really help you...sorry...) but, it's really quite simple. Basically, you are putting the commands that you would normally type at the prompt, all into one file, and just giving them a certain syntax. Try it - I think you'll enjoy learning it.


Dark Ninja

milanuk
10-18-2001, 07:28 PM
Dinking around looking at the Advanced Bash Scripting Guide (not in front of an actual *nix box), it looks like I need to start w/ something like this?

#!/bin/sh

if ps aux | grep dnetc
then echo "distributed.net client already running"
else cd ~/dnetc && ./dnetc --quiet && echo "distributed.net client started"
exit

This is just off the cuff -- probably full of glaring errors. I'm kind of assuming that the exit status for grep is 0 when it finds dnetc. If not, I guess I'll have to try something else. This version is kind of interactive... it gives some feedback. I would probably strip out the 'echo' statements for the cron version.

Any ideas or help would be greatly appreciated.

TIA,

Monte

milanuk
10-18-2001, 07:39 PM
Ok, ok. Modified it a little and tested the first part on a NetBSD shell account running bash. Forgot that I needed the 'if/fi' bit, changed that, and then found out about the '-q' or '--silent' flag for grep to suppress printing output to the screen... not needed w/ the echo statements, and especially not later when it ends up in cron ;)

Here's what I have working so far (modified for a host that does have screen, but not dnetc, so I tested for screen instead)

#!/bin/sh

if ps aux | grep -p screen
then echo "screen already running"
# else cd ~/dnetc && ./dnetc --quiet && echo "screen started"
fi
exit


Again, suggestions or comments, please.

Monte

stiles
10-19-2001, 01:25 AM
you need a test for your if else statement to work as intended

if [ -z `ps aux | grep "screen"` ]
then cd ~/dnetc && ./dnetc --quiet
fi
exit

that should be close