Setting up a terminal for SSH and QP2TERM Access

I was discussing the use of shells on the Ryver forum for #IBMIOSS with a colleague who wanted to be able to use one shell for his QP2ETRM access and another for his SSH access. I have had numerous issues in the past when setting up Node.js which I had documented in previous blog posts related to using the .profile file to set environment variables etc. The question this time was how to set up the bash shell (Option 7 (tools) for 5733OPS) for SSH access while using the Korn Shell (ksh) for QP2TERM access automatically on sign in (you could always call bash from the ksh shell to switch.

Kevin Alder kindly put me straight on which shell was which and which shell was the default for QP2TERM so we all learned something that day. Previously I had been looking at how to set up the key functions in ksh as part of another test I was doing so I felt that this should be something that would fit nicely into the .profile file used for setting up the environment by user.

The answer came from a post on another site where the user was trying to find out if the request was a batch or interactive request. They used the tty -s function to determine type of request that had caused the terminal to be launched. From there we can sense if this is a SSH terminal or if it is being run from QP2TERM (needed to experiment to confirm the difference as I was not sure at the time) and set the shell accordingly. Kevin did mention using exec as the launch method for the shell as it would reduce the number of jobs on the system so I took that as being a good option.

Before you set up your .profile file you need to make sure your user profile is set up correctly. By default a profile is set to have a directly of ‘/home/*USRPRF’ where *USRPRF is the profile used. In my case that would be ‘/home/CHRISH” (note the upper case). When a profile is created it does not automatically create this directory for you so you would need to create it before creating the .profile file. I tend to create a lowercase path such as ‘/home/chrish’ and change the HOMEDIR setting for the profile to reflect that.

The following is the content of the file I created in my home directory, make sure you set the CCSID of the file to 819 (ASCII) and the content is ASCII based. Another trap I have fallen into before is using EDTF can create some issues so if possible use an alternative ASCII based editor such as notepad++, vi, etc.

if tty -s

then

echo terminal session

else

echo Non Terminal session

fi 
I then ran the test to see what the output would be from a putty terminal and from the QP2TERM session. The QP2TERM session showed ‘Non Terminal session’ and the putty session showed ‘terminal session’. Now all that I needed to do was add the relevant code to launch a bash shell when it was a terminal session and do nothing when called from QP2TERM.

if tty -s

then

PATH=/QOpenSys/QIBM/ProdData/OPS/tools/bin:$PATHexec bash                                      
fi 
Now when I start the putty session I get a bash shell. QP2TERM still uses the ksh shell.

Chris…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.