dimanche 30 novembre 2014

Checking and Killing processes of a user before deleting


I am working on a script to delete users from text file. However, before deleting, I wanna check if any process by a user is running and if running then kill all the processes and delete. Here's how, I'm doing this..



if
#user doesn't exists then print user not exist
else
pids = `ps U "$name" -o pid | head -n -1`
if [ -n "$pids" ]
then
for pid in $pids
do
sudo kill -KILL $pid
done
fi


sudo userdel

$name -r -f
echo


echo "The user - $name - has been deleted!"
echo
fi
done < "$fname" # double-quote fname
echo


So, basically its a loop to delete users and in that an if statement to make sure no process is being run by a user and if its being run then force close processes and delete user.


However, Its not working and it says pids: command not found.. Any solution, how to fix it? I'd appreciate your help, Regards



Aucun commentaire:

Enregistrer un commentaire