01-23-04 10:36 PM
Materialised <materialised@privacy.net> writes:
quote:
> upon executing this script i get the warning message
>
> ./process.sh: line 11: syntax error near unexpected token `fi'
> ./process.sh: line 11: `fi'
>
> Does anyone know why?
Because you forgot 'then':
quote:
> if [ "$i" -ge 8 ]
thenquote:
> kill `ps aux|grep joe | awk '{print $2}'`
> fi
The 'grep joe' is very bad: if you happen to have users 'joe' and
'joeshmoe', the latter will get killed without any warning
whenever the former exceeds his process limit.
Further, this script may kill arbitrary process:
if any of the processes selected by 'grep joe' terminates before
kill begins; and it's PID is recycled for some new and unrelated
process, you can kiss that new process goodby :-(
quote:
> Also how would it be possible to have a plain text file simply
> containing user names, and have the script read from that in a loop
> and make the checks as detailed above? As this would save me from
> having to add to the script each time a new user was added.
A better way would be use /etc/passwd (assuming you are not using NIS):
that way you would not have to add to the "plain text file" every
time a new user is added.
Start by reading the "Advanced Bash Scripting Guide" at
http://www.tldp.org/LDP/abs/html
Then do something like:
sed 's/:.*//' /etc/passwd | while read user; do
## whatever with $user
done
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
[ Post a follow-up to this message ]
|