[bash] if statements in a loop
I'm trying to scan the process list for multiple things, and if one of those things is found then I want it to log the entry and kill it. This is what I have so far, but its unacceptable because it wont identify which one of the processes was found, only that ONE was found.
Code:
function myfunc() { It also needs to be a loop so the script can continue to scan even after its found its target and killed it. Thanks for reading, hopefully you guys can help :) |
Firstly, the if-statement as you have given it will only return true if both variables have been assigned. To execute the then block if either are assigned, the tests should be:
Code:
if [ $process1 ] || [ $process2 ]; then Code:
while [ 1 = 1 ]; do Code:
rob:~$ gedit & Hope this helps, Rob |
Code:
function myfunc() { Thanks |
Quote:
To only attempt to kill the process if it exists, you could use: Code:
[ $process1 ] && kill -9 $process1 && echo Process $process1 killed >> /var/log/test.log Code:
unset process1 |
All times are GMT -5. The time now is 10:30 PM. |