Informing the IBM Community

Customisation for the VIOS CLI

0
(0)

Web development concept: Gears on digital background

Something I’ve discussed previously but have refined recently is customising the VIOS CLI take make using the CLI and navigation a little easier.

Whenever I install a VIOS LPAR the first thing I do is add in a couple of files I keep handy to do a few things for me:

● Amend the CLI prompt to show the VIOS host name and the current directory
● Create an alias for the oem_setup_env command
● Create an alias to run VIOS commands whilst in root mode
● Set my command line mode to vi so that I can use keyboard shortcuts
● Set VIOS so that it automatically places its host name in the title bar of my Putty session

There are a few other bits but these are the main items. In this article I’ll describe the above items and provide my scripts and how to install them.

The two files we need to install are the .kshrc and .profile.padmin files. Note that the leading “.” is required. The source code for each of these files can be found at the end of the article.

 

Amend the CLI prompt

By default your CLI prompt will show the # or $ sign. There’s no indication of which directory I’m currently in or which VIOS I’m using. By amending the PS1 variable we can customise the prompt. In the .kshrc file the line:

fig 1 GR May

We can replace the prompt so that it shows who we’re logged in as, the VIOS host name and the current directory we’re in. You’ll notice some strange characters following the $NODE and $PWD variables.

Many of my VIOS installs use shared storage pools which requires the host name to be a fully qualified domain name. Having vios1.mycompany.local on the prompt is too much. The %%.* characters strip out the domain name so that just the host name is displayed on the prompt.

Similarly the ##./ characters after the $PWD variable strip out the leading path names. So, if my current directory is /home/padmin/config then the prompt would only show config by stripping out the /home/padmin/ text.

 

Add the aliases

IBM are not keen on us leaving padmin mode and going in to root mode but quite often we have to. Typing oem_setup_env to get in to root mode is cumbersome. So by adding:

fig 2 GR May

I can simply type aix whilst in padmin mode to take me to root mode.

When I’m running in root mode I may want to run a VIOS command such as lsdev -slots. In order to do this I need to access the VIOS commands which are accessed using the ioscli command in /usr/ios/cli:

fig 3 GR May

Now, when I’m in root mode, I can enter:

fig 4 GR May

This will run the VIOS command even though I’m in root mode.

 

Set vi command mode

vi is an editor you will find in all *nix operating systems. It’s old, it’s clunky but it is very powerful and it also has many keyboard shortcuts for navigation. These keyboard shortcuts can be used on the CLI to do things like searching for a previously executed command or replacing specific characters on the current command line.

I won’t go in to the vi keyboard shortcuts as there are many article online discussing this in detail.

By using:

fig 5 GR May

I enable the vi command mode and keyboard shortcuts. ESC+k, for example, scrolls through your previously execute commands. This is similar to the F9 key on IBM i.

 

Write the host name to the Putty window title bar

At the end of the .profile.padmin file there’s a section of text which retrieves the VIOS host name and then uses the a variable called PROMPT_COMMAND to write the host name on the title bar of your Putty session. I find this really handy as often I have many Putty sessions open and it helps to assist with identifying which VIOS I am logged in to.

In order to get this to work you should configure your Putty session so that it is a terminal type of xterm or, preferably, xterm-R6.

 

Installing the customisations files

The two customisations files shown below can be installed as follows.

Type:
oem_setup_env

this takes you to AIX mode

Type:
vi .kshrc

This opens up the vi editor.

Press i to insert and then copy and paste in the commands in the .kshrc file shown below.

With the data copied in to the vi editor save and close the file by pressing:
ESC:wq

That’s Escape key, then a colon then the letters wq.

You will now be back at the command line.

We now need to amend a VIOS file to ensure that our customisations are enabled each time we log in.

Type the following commands whilst in oem_setup_env mode:
chmod +w /usr/ios/cli/.profile
vi /usr/ios/cli/.profile

You will now see the contents of the .profile file. We need to add a new line to the end of this file. Ignore the double quotes in the next three lines:

type “G” to to very last line in file
type”$” to go to the end of the line last line
type “a” to add line, then press enter

Add to last line:
. $HOME/.profile.padmin (copy from leading . to n)

Now save your changes to the file:

ESC:wq

Type:

fig 6 GR May

NOTE: If you update your VIOS to a new release the .profile file will be replaced. You will need to edit the .profile file after a VIOS upgrade to add the . $HOME/.profile.padmin line again.

Now we need to add our second file to VIOS to complete our customisations.

Type;

fig 7 GR May

This will open a vi editor showing an empty file.
Press i to insert and then copy and paste in the commands in the .profile.pdmin file shown below.

With the data copied in to the vi editor save and close the file by pressing:
ESC:wq

That’s all done. You will need to log out of VIOS completely and log back in again to see the customisations working.

This all seems a little complicated but in most cases I can get the files installed and the .profile file updated in just a couple of minutes, it depends how comfortable you are with vi.

 

The files

.kshrc

# Prompt
# set a prompt that shows the user name,
# the machine name and the current directory

if id >/dev/null 2>&1 ; then
export USER=root
else
export USER=$LOGNAME
fi
####export PS1='$USER@$NODE:$PWD '
export PS1='$USER@${NODE%%.*}:${PWD##*/} '
# Extend alias list
alias aix="oem_setup_env"
alias i=/usr/ios/cli/ioscli
set -o vi

resetrmc () {

        rmcctrl -z

        rmcctrl -A

        rmcctrl -p

}

 

.profile.padmin

#### root/padmin base settings on VIO servers
## EXPORTS ##
# PATH
export PATH=$PATH
export ENV=$HOME/.kshrc
# get the machine for the prompt
export NODE=$(hostname )
# ignore CRTL-D when in login shell
set -o ignoreeof
set -o vi

#Create an alias to display fc WWPNs. Use command getwwn in as padmin.
function getwwn { for i in `lsdev | grep fcs | awk '{print $1}'`; do lsdev -vpd -dev $i | grep Network; done }

# Set up server name to display un Putty Window Title bar

export SERVER=$(hostname)

case "$TERM" in

xterm*|rxvt*)

 PROMPT_COMMAND="\033]0;${SERVER}\007"

 echo $PROMPT_COMMAND

 ;;

*)

    ;;

esac

 

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.