Home > Linux > Unix shell scripts – Display Logged in users and who is using high CPU percentage

Unix shell scripts – Display Logged in users and who is using high CPU percentage

August 18th, 2010 Leave a comment Go to comments

Bash script ini berfungsi untuk menampilkan sedikit informasi mengenai user-user yang baru saja login dan apa yang mereka lakukan.
Source code : loggedin.sh

#! /bin/bash

w > /tmp/a

echo "Total number of unique users logged in currently"
cat /tmp/a|  sed '1,2d' | awk '{print $1}' | uniq | wc -l
echo ""

echo "List of unique users logged in currently"
cat /tmp/a | sed '1,2d'|  awk '{print $1}' | uniq
echo ""

echo "The user who is using high %cpu"
cat /tmp/a | sed '1,2d' | awk   '$7 > maxuid { maxuid=$7; maxline=$0 }; END { print maxuid, maxline }' 

echo ""
echo "List of users logged in and what they are doing"
cat /tmp/a

Jalankan : ./loggedin.sh

Total number of unique users logged in currently
1

List of unique users logged in currently
tux-kecil

The user who is using high %cpu
0.00s tux-kecil    ttyp1    118.96.149.36    05:38    0.00s  0.08s  0.00s /bin/bash ./log

List of users logged in and what they are doing
 09:21:19 up 2 days, 23:37,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
tux-kecil    ttyp1    118.96.149.36    05:38    0.00s  0.08s  0.00s /bin/bash ./log
Categories: Linux Tags:
  1. akhi_tangguh
    August 19th, 2010 at 18:01 | #1
    Using Mozilla Firefox Mozilla Firefox 3.6.3 on Windows Windows XP

    kalau mau bikin file instaler aplikasi pakai SH gimana yaaaa?

  1. No trackbacks yet.

*

Bad Behavior has blocked 1472 access attempts in the last 7 days.