[EMAIL PROTECTED] wrote:
I'm trying to get a pidof a php script by capturing the path:
like /home/somebody/my_script which will be the first arg. to the bash script
Could anybody tell me what's wrong with this script ?
I'm new to scripting in general so any help would be apreciated !
#!/bin/bash
1st_arg=$1
prosesses=`lsof -i`
prosessid=`echo $prosesses | gawk /1st_arg/'{print $2}'`
echo $prosessid
if [ -z "$prosessid" ]
echo "not running"
fi
exit 0
Regards
Lars Sorensen
It would write it like this (although yours almost works):
--- CUT ---
#!/bin/bash
pid=`lsof -i | grep "$1" | awk '{print $2}'`
if [ -z "$pid" ]; then
echo "not running"
exit 1
fi
echo "$pid is running"
--- CUT ---
This would handle characters that would normaly have to be escaped a little better and provides a non-zero error level if your process isn't running. You could then use this script within other scripts if you wanted, like this:
--- CUT ---
if ! /somewhere/checkpid ; then
dosomething
fi
--- CUT ---
Although, I think the only thing wrong with your script is that it doesn't have a "; then" after the "if [ xxx ]" statement.
Good luck!
- Ryan
--
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list