Operating System - HP-UX
1825777 Members
2132 Online
109687 Solutions
New Discussion

Limiting "sudo kill" to killing only user processes

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor

Re: Limiting "sudo kill" to killing only user processes

>Is there a way to restrict the input to accept only numerical entries and no wildcards?

 

The script has no idea if there were wildcards but it can validate the input.

You could use pattern matching to check:

if [[ "$pid" != [0-9][0-9]* ]]; then

   echo "Invalid PID: $pid"

   continue

fi

And you can optimize the pattern match with:

if [[ "$pid" != +([0-9]) ]]; then

 

>The comparison != is for strings, while -ne is for numbers.

 

Right.  If you like != so much, you can always use:

(( $? != 0 ))

TheJuiceman
Super Advisor

Re: Limiting "sudo kill" to killing only user processes

Thank you all very much for your help. The script looks and runs beautifully. I'm sure someone else will find this useful as well. Much appreciation and respect gentlemen!!!