Syntax Error?

Hi, I'm working on a short script involving listing the names of users and processes they're running at the moment. The problem is my script is giving me an "if: Expression syntax" error. Here's what's in my script so far:

#!/csh/bin
ps -af > Proc
who > Wholist

set usrnm = `awk '{print $1}' Wholist`
set cmdnm = `awk '{print $1}' Proc`

foreach line{`cat Wholist`}
if ( $usrnm == $cmdnm ) then
echo "$line . `awk '{print $8}' Proc'"
endif
end

//

I don't know what happens, but it always gives me the "if: Expression syntax" error. Is there a problem in the way I typed it?

Thanks for your time.

I don't know if this is it but it is always better to use quotes:

if ( '$usrnm' == '$cmdnm' ) then ...

in case one var gets expanded into something wierd (with spaces etc.)

HTH

Suggest you also change the first line - should be #!/bin/csh
and get in the habit of putting commands with full path so changes later will not effect your script.

/usr/bin/ps -af > Proc
instead of
ps -af > Proc

try this:

ps -ef | awk '{print $1, $9}' | sort -u

gives the list of users and what they are doing. Let me know if this helped

Yeah, about that one, it gives me "Badly placed ()'s" when I try that.. Thanks for your input, though.

Hmm, I tested it out, but as per the result, it does show all results, but also lists the usernames on their own line as well. Also, there are a lot of these results for me to keep up with, so I guess that's a bit of a strain on the eyes, too. Thanks, though!

^^; Yeah, whoops, I actually did have #!/bin/csh. I just mistyped it. I admit I'm still kinda new to scripting.
As for the ps -af > Proc, I tested that part and that was working fine. The errors were in the "IF" parameters. Thanks for your input, though.

Using ksh and Solaris, it's *easy* to do things like this on the fly without temporary files...

$ who | awk '{print $1}' | sort | uniq | while read username; do
>   uid=`/usr/xpg4/bin/id -u $username`
>   echo "$username"
>   echo "==============="
>   pgrep -l -u $uid
> done

Cheers
ZB