Thursday 18 April 2013

Show running processes and uptime on the HMC in the restricted shell

The HMC restricted shell doesn't include the "ps" or "uptime" commands which are sometimes very helpful when troubleshooting issues.   Below are a couple of methods to list running processes and find the HMC uptime.

List Running Processes

The HMC is based on Linux, and the Linux kernel stores information about running processes under /proc.   Each running process has a process ID number (PID) and information about each PID is available at /proc/<pid>.  

Based on this, we can create a primitive "ps" command by listing information from each process out of the /proc filesystem using a command like this:
for proc in `ls -d /proc/[0-9]* | sed 's/\/proc\///g'`; do  printf "%-10s" $proc; cat /proc/$proc/status | grep Name | sed 's/Name://g'; done
When you run this, 2 columns are displayed, the first is the PID number, and the second is the command being run.

Here is what the output looks like (I piped it to the "head" command so that only the first 10 lines are shown):
hscroot@hmc1:~> for proc in `ls -d /proc/[0-9]* | sed 's/\/proc\///g'`; do  printf "%-10s" $proc; cat /proc/$proc/status | grep Name | sed 's/Name://g'; done | head
1             init
10            khelper
10266         su
10267         browserjail
10268         firefox
10278         firefox
10286         run-mozilla.sh
10290         firefox-bin
10313         cimserver
10314         cimservermain

Showing the HMC uptime

There are a couple of methods to show the uptime on the HMC from the restricted shell:

You can run "cat /proc/uptime"; the first column listed is the number of seconds the system has been up.   In my opinion this is much better than "who -b" which is described next.
hscroot@hmc1:~> cat /proc/uptime
60182.47 118695.32
Another option is "who -b" which will show the date/time of the system boot based on /var/log/wtmp.  Personally, I don't think this is a very reliable way to do it as it relies on the /var/log/wtmp file.   
hscroot@hmc1:~> who -b
         system boot  2012-11-03 01:52
If you want to convert the /proc/uptime from seconds to days, you can use a command like this which will show the number of days the system has been up:
echo  $(( $(printf "%.0f" "$(cat /proc/uptime | cut -d " " -f 1)") / 60 / 60 / 24))
If you found these commands helpful, you might want to check out EZH - The Easy HMC Command Line Interface.   It provides a simplified, easy to use interface to the HMC command line and includes "uptime" and "ps" commands similar to what is in this posting, plus dozens of other easy to use commands.

 It is very easy to install, and runs within the HMC restricted shell without having to make any modifications to your HMC.   Check it out at http://ezh.sourceforge.net/  There is also a video overview/demo of EZH at http://youtu.be/E8A9s1_i9xA  Below is the list of included EZH commands in the latest version and the corresponding native HMC commands:

LPAR level commands, all start with "lpar".   After EZH install, type "lpar" and hit tab twice to see all commands listed
FunctionEZH CommandHMC Native Command
Open a virtual terminallparconsole aix1mkvterm -m p520 -p aix1
Close a virtual terminallparconsoleclose aix1rmvterm -m p520 -p aix1
Show LPAR/profile infolparinfo aix1lssyscfg -r prof -m p520 --filter lpar_names=aix1
lssyscfg -r lpar -m p520 --filter lpar_names=aix1
Show command to re-create LPAR
(Can be used to easily clone LPAR)
lparclone aix1No native HMC command available
Show frame an LPAR is onlparframelookup aix1No native HMC command available
Display list of LPAR's and Managed systems
and there current state
lparlsNo native HMC command available
Save running LPAR configuration to profilelparsaveconfig aix1mksyscfg -r prof -m p520 -o save -p aix1 -n aix1 --force
Run VIO command ("
lsmap -all" in this example)
lparviorun vio1 lsmap -allviosvrcmd -m p520 -p vio1 -c "lsmap -all"
Power on LPARlparpoweron aix1

Optionally specify profile
 as second parameter
(if not uses default profile)
chsysstate -r lpar -o on -f aix1 -m p520 -n aix1
Power on LPAR to SMSlparpoweronsms aix1

Optionally specify profile
 as second parameter
(if not uses default profile)
chsysstate -r lpar -b sms -o on -f aix1 -m p520 -n aix1
Power off LPAR - Operating System shutdownlparshutdownos aix1chsysstate -r lpar -o osshutdown --immed -m p520 -n aix1
Power off LPAR - hard shutdownlparshutdownhard aix1chsysstate -r lpar -o shutdown --immed -m p520 -n aix1
Delete LPARlpardelete aix3rmsyscfg -r lpar -m p520 -n aix3
List LPAR system attention LED statuslparlsled aix1lsled -m p520 -r sa -t virtuallpar --filter lpar_names=aix1
Clear LPAR system attention LEDlparclearled aix1chled -m p520 -r sa -t virtuallpar -o off -p aix1
Display reference code on LPARlparrefcode aix1lsrefcode -r lpar -m p520 -F "lpar_name refcode time_stamp" --filter lpar_names=aix1
Managed system level commands, all start with "frame".   After EZH install, type "frame" and hit tab twice to see all commands listed
FunctionEZH CommandHMC Native Command
List managed systems attached to HMCframelslssyscfg -r sys -F name
Power on managed systemframepoweron p520chsysstate -m p520 -r sys -o on
Power off managed systemframepoweroff p520chsysstate -m p520 -r sys -o off
List attention LED status on managed systemframelsled p520lsled -m p520 -r sa -t phys
Clear attention LED on managed systemframeclearled p520chled -m p520 -r sa -t phys -o off
List managed system details, CPU, and memoryframeinfo p520lssyscfg -r sys -m p520
lshwres -r proc -m p520 --level sys
lshwres -r mem -m p520 --level sys
List servicable events for a managed systemframelsevents p520lssvcevents -t hardware -m p520 --filter status=open
Misc. Commands
FunctionEZH CommandHMC Native Command
Show system uptimeuptimeNo native HMC command available
List running process PID's and namespsNo native HMC command available
Show available memory/swapfreemonhmc -r mem -n 0; monhmc -r swap -n 0
Count number of lineswc -lNo native HMC command available
Edit a filevirnvi -f
Check disk usagedfmonhmc -n 0 -r disk
Source a file.source
List LED status of all frames and LPAR'slsledallNo native HMC command available
List open serviceable eventslseventslssvcevents -t hardware --filter status=open
Close all serviceable eventsclosealleventschsvcevent -o closeall
Show HMC versionhmcversionlshmc -V
Reboot HMChmcrestarthmcshutdown -t now -r

0 blogger-disqus:

Post a Comment