sintax is more like:
if [ test ]
then
bla bla bla
fi
so ";" is the equivalent of a new line.
raymundo
David Simmons wrote:
I have noticed in this thread that everyone is putting a ";" after their
tests: if [ test ] ; and for [ test ] ;
When is the ";" required or is it always required after the test in a
conditional statement?
Thanks,
Dave Simmons
-----Original Message-----
From: Raymundo M. Vega [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 05, 2003 11:00 AM
To: [EMAIL PROTECTED]
Subject: Re: Bash script help ?
I think several lines are not quite right:
- regular expression in gawk should be inside the {}, but
you will have to pass the argument to gawk.
- next line after if should be then, it is usually used like
if [ -z "$processid" ] ; then
the script will only echo first time it finds the string, if you have
several instances of the same string, then you need a for loop like:
======================= #!/bin/bash
processid=`lsof -i | grep $1 | gawk '{print $1}'`
for proc in $processid ; do
[ -z "$proc" ] && "echo not running"
done
========================
hope it helps
raymundo
Ryan Babchishin wrote:
[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