PDA

View Full Version : script help



The_Jaymz
6th April 2006, 02:15 AM
i'm having a hell of a time with a bash script
i'll set a cron job to run it periodically
it needs to check to see if a program is being run and by a specific user
if it's not running, it needs to start it.

the program is named ./server and it's in each user's home directory
each user will have their own crontab to run the script

i know it starts with ps and grep, but i just can't figure out a way to make this work

can anyone help please?

daverj
6th April 2006, 04:40 AM
provide a little more information. What part are you having trouble with? Seeing if the program is being run? Running it from the script? Let us know and we will help.

Dave

Firewing1
6th April 2006, 04:45 AM
Why each user / what does this script do? I'm sure there are easier ways...
Firewing1

Firewing1
6th April 2006, 04:57 AM
OK, found something that migh help:
ps -A U admin
list all processes running by admin. So, you could do:

homes="$(ls -1 /home)"
echo $homes | while read line;do\
PID=$(ps -A U "$line" | grep "/bin/bash" | grep "server"$ | awk '{printf $1" "}')
kill -SIGKILL $PID
sh $line/server
done
That's assuming that
#!/bin/bashis at the beginning of ./server
Firewing1

The_Jaymz
6th April 2006, 08:23 AM
sorry i didnt give enough info. and thanks for the help so far... here's some more info...
this is not a command, it's a program that each user will compile and run. it doesn't let you tell it what configuration file to use....so all of that is compiled in. say there are 3 users... one two and three...
user one has his executable, "server" in his home directory; as do users two and three... i need a script that I can give to all the users that will see if their instance of "server" is running, and if it's not will start it. this script it going to be set up as a cron job for each user though. thanks for your help guys....scripting...and programming in general has always been hard for me... networks seem to make sense though... thanks again...if you need any more info, you can contact me here: james.mcse AT gmail DOT com