I need to know, at any given time, how many unique users are connected to a redhat server. The following commands accomplish this easily:
who | awk '{ print $1 }' | sort -ud | wc -l
However, I need this functionality within a perl script, so that a network monitoring utility can run it at scheduled times, and track the number of unique connections over time.
While I would like to learn scripting with perl, I have no idea how long it would take to learn to script this myself, and I don’t have enough time to dedicate to learning perl at the moment. Any assistance in creating a perl script with the above functionality would be greatly appreciated.
To easily wrap this into a perl script, do this:
Be sure to escape $1, or else it will be interpolated by Perl.
What you do with $result after that depends on what exactly you’re trying to do. You could average it over time, store every result in a file or database…it really depends on what you want to do with the result once you have it. If you’d care to provide more details I can offer some advice.