The following is a script to kick the user out of the system:
#! /Bin/bash
Read-p "input your username" user
Ps aux | grep "^ $ user" | awk '{print $2}'>/opt/killuser // find a user's process and extract the process number
DAT = 'cat/opt/killuser'
For I in $ DAT // assign the process to the variable DAY
Do
Kill-9 $ I &>/dev/null // kill the pid corresponding to the process ID
Done
Rm-rf/opt/killuser
Explain the meaning of the script:
$ User: this variable is easy to understand and assign values to the keyboard. If you don't understand it, you can find the information.
For example, if the user currently logged on is lee, print the pid of the lee user, and extract the keyword awk to obtain the pid.
[Lee @ redhat root] $ ps aux | grep lee | awk '{print $2 }'
1878
1879
1900
1901
1902
[Lee @ redhat root] $ echo $ USER
Lee
Ps aux | grep "^ $ user" | awk '{print $2}'>/opt/killuser exports the extracted pid to a file.
Use kill-9 to force the kill.