The first thing you should know about scripting in csh
is that it is usually a very bad idea. That said, if you insist, the problems with your script are:
csh
doesn't support the $()
construct for command substitution, use ` `
instead.
csh
doesn't support the for i ... do ... done
syntax, use foreach i ... end
instead.
csh
doesn't do funky string manipulation like "${elapse%:*}"
. You'll have to get around it using some other tool.
- I don't know how to get
[
to work with csh
(but it's probably possible), as a workaround, use if
instead.
So, a working version of your script in csh
would be:
#!/bin/csh
set ALTER = "$1"
set NAME = "$2"
foreach pr (`pgrep "$NAME"`)
set elapse = `ps -o etime= -p "$pr" | cut -d: -f1`
if ( "$elapse" > "$ALTER" ) echo "$pr"
end
Seriously though, don't script in csh
, it will only cause you pain. Especially since all you really need is:
ps -o pid=,etime= -p $(pgrep $NAME) | cut -d: -f1 |
awk -vval="$ALTER" '$2>val{print $1}'
csh
is just painful and should be avoided at all costs really.