Clear all users except the current login user

Source: Internet
Author: User
The problem is as follows: clear all users except the current login user. Result: 23: 00: 17up1: 08,1 user, loadaverage: 0.02, 0.05, 0.02 USERTTYFROM & n The problem is as follows:
Clear all users except the current login user
Processing result:
23:00:17 up, 1 user, load average: 0.02, 0.05, 0.02
User tty from login @ IDLE JCPU PCPU WHAT
Root pts/1 192.168.1.100 0.00 s 10.75 s 0.00 s w
Only yourself is left on the machine :)

Method:

 
  1. #! /Bin/bash a = 'echo $0 | sed's /.. \(... \). */\ 1/''' for I in 'w | awk-v B = $ a' NR> 2 {if ($ NF! ~ B) print $2} ''Do echo $ I fuser-k/dev/$ I done
Practice:
, Pts/1 is the current user, that is, the user to be retained.
Execute the script:./kill. sh (this script is the script given above, and the script name is defined by yourself)
, All connections except for the command execution are interrupted.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.