Display the number of logged on users on OES and create a log file

0 Likes

Sometimes it's handy to know how many people are logged into an OES server. We also like to have logging turned on so we know how high the utilization is at different times of the day. It's very easy to create a script for this thanks to ncpcon.



The first script just lists who is logged on and how many there are:



cat /usr/bin/oesusers

#!/bin/sh
# This is a script that shows what users and how many are logged into a open enterprise server.
clear
echo "These users are logged in right now:"
# The command below uses ncpcon to list all connections to the server. We then grep CN, NOT LOGGED IN to weed out some unwanted connections.
# cut -f 2 cuts out the part we want. We then use sort to get it nice and tidy for removing duplicate entries with uniq and lastly we use
# grep to remove entries with a * infront of them. wc -l counts lines wich tells us how many users there are.
# "grep -v computerou " weeds out computers from the list so we are left with only users
ncpcon connection list | grep CN | grep -v NOT | grep -v computerou | cut -f 2 | sort | uniq -i | grep -v [*]
echo " "
echo " "
echo "It is `ncpcon connection list | grep CN | grep -v NOT | grep -v computerou | cut -f 2 | sort | uniq -i | grep -v [*] | wc -l` users logged in at this moment."
echo " "
echo " "





The second script logs the number of connections and the load on the server to /var/log/oesusers.log:



cat /usr/bin/oesload 

#!/bin/sh
inloggade=`ncpcon connection list | grep CN | grep -v NOT | grep -v cumputerou | cut -f 2 | sort | uniq -i | grep -v [*] | wc -l`
# In grep -v cumputerou replace computerou with the name of the container where you store your computers
load=`top -b -n 1 | grep Cpu | cut -f 3 -d " " | cut -f 1 -d "%"`
date=`date %Y-%m-%d*%k:%M`
echo $date, $inloggade, $load >> /var/log/oesusers.log





To use the script put it in /usr/bin/oesload. Do a " chmod x /usr/bin/oesload " and put this line into /etc/crontab



0 */1 * * *     root /usr/bin/oesload




Now you will log the number of people logged in and the load once an hour.




Tags:

Labels:

How To-Best Practice
Comment List
Anonymous
  • For this we use MikoTik's "The Dude" www.mikrotik.com/thedude.php (Free!) and use it to monitor all of our servers via SNMP. In addition to monitor the servers CPU, memory, disk, network, etc and making nice graphs we extended SNMP to monitor both concurrent users and open files. Below are parts of various config files we used to make it work. Keep in mind that once these values are exported in SNMP you can use your SNMP monitor of choice to watch and graph values.

    snmpd.conf on the OES server
    ----------------------------------
    exec .1.3.6.1.4.1.31337.1.1 ncpcount /scripts/snmpcmd.sh ncpcount
    exec .1.3.6.1.4.1.31337.1.2 openfiles /scripts/snmpcmd.sh openfiles
    ----------------------------------

    /scripts/snmpcmd.sh on the OES server
    ----------------------------------
    #!/bin/bash

    if [ $1 = "ncpcount" ]; then
    ncpcon connection 2>/dev/null | grep "Licensed Connections" | egrep -o "[0-9]+"
    fi

    if [ $1 = "openfiles" ]; then
    ncpcon stats 2>/dev/null | grep "open files" | egrep -o '[0-9]+'
    fi
    ----------------------------------

    the dude custom functions on the dude server
    ----------------------------------
    name: novell_ncp_openfiles
    code: oid("1.3.6.1.4.1.31337.1.2.101.1")
    ----------------------------------
    name: novell_ncp_users
    code: oid("1.3.6.1.4.1.31337.1.1.101.1")
    ----------------------------------

    the dude custom probs on the dude server
    ----------------------------------
    name: NCP Connections
    avaliable: novell_ncp_users()
    error: ""
    unit: Count
    rate: none
    ----------------------------------
    name: NCP open files
    avaliable: novell_ncp_openfiles()
    error: ""
    unit: Count
    rate: none
    ----------------------------------
Related Discussions
Recommended