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?
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.
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.