OpenSUSE Linux Tips, tricks, how-tos, opinions, and news
My Resume - My LinkedIn Profile - twitter: @scottmmorrisAs Linux tools sometimes do, this little script was born out of frustration from the repetitive. And the meniality of the task is directly proportional to one’s desire to replace it with anything that will automate the process. If I have to do something twice on my Linux box, it gets automated.
So a few days ago I put together a bash script which I named “What’s Up?” The abbreviation for this is ‘sup’ which is the command used to invoke the script. I use it to tell me which server I’m on, who I’m logged in as, the memory status of the box, and some other crazy junk.
Originally, this fool was 110 lines of code to display 13 lines of output. Fortunately, an altruistic and knowledgeable Lonnie Olson brought to my attention the fact that there was room for some nice optimizations. Of such coolness were these optimizations that they brought the line count from 110 to a mere 21, not including comments and empty lines.
If you’re just tuning in, the script looks like this:
#!/bin/bash
# ORIGINALLY WRITTEN BY SCOTT MORRIS (http://www.suseblog.com/) on 2008-05-28
# UPDATED AS SUGGESTED BY LONNIE OLSON on 2008-05-30
# COLLECT SOME INFO
IFS=$'n'
UPTIME=`uptime`
D_UP=${UPTIME:1}
MYGROUPS=`groups`
DATE=`date`
KERNEL=`uname -a`
CPWD=`pwd`
# OUTPUT THE DATA
printf " user:tt"$USER" (uid:"$UID")n"
printf " groups:t"$MYGROUPS"n"
printf " working dir:t"$CPWD"n"
printf " home dir:t"$HOME"n"
printf " hostname:t"$HOSTNAME"n"
ip -o addr | awk '/inet /{print " IP (" $2 "):t" $4}'
printf " date:tt"$DATE"n"
printf " uptime:t"$D_UP"n"
printf " kernel:t"$KERNEL"n"
printf " cpu:tt"$CPU"n"
free -mot | awk '
/Mem/{print " Memory:tTotal: " $2 "MbtUsed: " $3 "MbtFree: " $4 "Mb"}
/Swap/{print " Swap:ttTotal: " $2 "MbtUsed: " $3 "MbtFree: " $4 "Mb"}'
NOTE: If you copy and paste the above code and it does not work, just download it from the link provided above.
And its output looks like this:
[0137][scott@tomahawk:~]$ sup user: scott (uid:1000) groups: users dialout video working dir: /home/scott home dir: /home/scott hostname: tomahawk IP (lo): 127.0.0.1/8 IP (eth0): 192.168.0.110/24 date: Sat May 31 01:57:54 MDT 2008 uptime: 1:57am up 2 days 21:53, 5 users, load average: 0.27, 0.23, 0.18 kernel: Linux tomahawk 2.6.24-default #1 SMP Sat Jan 26 21:54:20 MST 2008 x86_64 x86_64 x86_64 GNU/Linux cpu: x86_64 Memory: Total: 940Mb Used: 925Mb Free: 14Mb Swap: Total: 1913Mb Used: 349Mb Free: 1564Mb [0157][scott@tomahawk:~]$
Logging into and out of many Linux servers per day with many different users can cause you to develop aggravated multiple personality disorders unless of course you use a cool script like this to cue the gray matter. I’m thinking about writing another one called ‘whoami’. Oh wait, someone already did that.
If you enjoyed this post, make sure you subscribe to my RSS feed!| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « Aug | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | ||
33 queries. 0.492 seconds
June 2nd, 2008 at 4:21 pm
Heh… Lonnie is da shiz-nigget. He rocks.
June 2nd, 2008 at 5:02 pm
Much like this guy Jason who is the all-knowing omniscience of all things great, powerful, programmatical, and everything else.
June 21st, 2008 at 10:32 am
The variable $CPU isn’t defined anywhere…
June 21st, 2008 at 1:05 pm
Kevin,
It is an environmental variable. Run “env | grep CPU” and you’ll see it defined.
November 29th, 2008 at 11:16 am
[...] is a fun bash script that will tell you "…which server you’re on, who you’re logged in as, the [...]