I am working on a script to delete users from text file. However, before deleting, I want to 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?