• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Bash Is Not A Shell Game

    September 17, 2014 Aaron Bartell

     It is interesting to observe where the IBM i side of IBM invests its resources. The operating system and database get a whole lot of investment, but the native application layer seemingly not nearly as much.

    Why? Because I don’t believe they see a viable future for modern applications being written in timely fashion with the likes of RPG. If that is true then what future does the platform have? The PASE environment on IBM i is the remaining hope for the operating system to live in the realm of modernity. Why? Because that’s where modern things are being ported to run. First we had commercially supported Java, then PHP, and now Ruby. They all run in PASE. This article will give an introduction for how to work with PASE from what’s called an SSH session so you can begin to be made comfortable with this different approach in interacting with the IBM i server.

    First let’s do some high level definitions of terms covered in this article:

    PASE–An AIX integrated runtime environment on IBM i. This is where Ruby runs. It does not include the AIX kernel, instead the IBM i kernel is called upon.

    SSH–A cryptographic protocol used to securely communicate from your laptop to a shell session on IBM i.

    Shell–A “shell” is a text-based interface that reads typed commands, runs them, and returns the output. Shell sessions are facilitated by IBM i jobs that you can view from WRKACTJOB. There are many different types of shells, each with its own flavors and utilities. Here we will be talking about what’s called the “bash” shell.

    Bash–An implementation of a shell based on the original Bourne shell (sh). Bash stands for “Bourne-again shell”.

    The IBM i ships with the Korn, Bourne, and C shells, which can be started by typing CALL QP2TERM from a 5250 terminal. If you’ve ever used the terminal capabilities of Linux or Mac OSX you will soon realize using the aforementioned shells through a 5250 telnet session is cumbersome at best. Instead it is preferable to use an SSH client from your laptop to a bash shell on IBM i because of additional features: tab-completion, command history with up/down arrows, and the ability to use server-side editors like joe.

    Starting SSH Daemon

    Before you can login with SSH you need to make sure the SSH daemon service is running. Issue the following command to start it and if it is already running then a simple diagnostic message will be displayed back to you.

    STRTCPSVR SERVER(*SSHD)
    

    The SSH daemon job runs in subsystem QUSRWRK, as shown below.

    You can now log in from your laptop with an SSH client. If your laptop is running Mac or Linux then you already have SSH client capabilities available through pre-installed applications (i.e., Terminal on Mac). If you are on Windows you will need to download a tool like Putty (free), as shown below. In the below screenshot the “user@192.168.168.76” is the IBM i profile and IP address. Clicking the Open button will start a session where you will be prompted for your IBM i profile’s password.

    Logging Into IBM i Via SSH Using PuTTY

    Below we see how to login from a Mac. After logging in, the pwd (print working directory) command is run so we can learn where we are at in the file system. The next command, echo $SHELL, is checking to see what shell we are using and in this case it shows bash. The bash shell utility doesn’t come with IBM i by default so the PowerRuby team has ported and included it with our installation (download your free copy here).

    Logging Into IBM i Via ssh Using Mac’s Terminal

    Each SSH shell session is tied to an IBM i job, as shown below. Take option 5 and peruse through the various attributes of that job to see what it has for values, library list, etc. It is important to realize what is going on here because it is significant. We logged into a Linux-like environment yet it is in entire submission to the IBM i operating system kernel that inherently gives us all the security, workload balancing, and other features we’ve come to rely on.

    Defaulting To Bash

    Now that you are logged in using SSH it would be good to learn some personalization options as it relates to your environment. For example, it is possible to make the PowerRuby bash shell your system-wide default.

    IFS file /QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-4.7p1/etc/sshd_config stores name-value-pairs of settings for SSH. You can edit the file with joe from an existing ssh session or EDTF from 5250 green screen, full commands shown below. Note that the joe editor is also included with the PowerRuby download.

    joe /QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-4.7p1/etc/sshd_config
    

    Or:

    EDTF '/QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-4.7p1/etc/sshd_config'
    

    Change the ibmpaseforishell line to look like the following:

    ibmpaseforishell=/PowerRuby/oss/bin/bash
    

    Here is a sample screenshot of what the joe editor looks like when editing the sshd_config file. The whole screen is editable and there is even syntax coloring for certain file extensions (i.e., Ruby files ending in .rb).

    After making changes to the sshd_config file you need to restart the SSH daemon with the following commands:

    ENDTCPSVR SERVER(*SSHD)
    STRTCPSVR SERVER(*SSHD)
    

    Sometimes it isn’t a reality to change system-wide settings and instead you may need to only change your profile to be defaulted to a different shell. This can be easily done by creating a .profile file inside your home directory and then adding the below shell script code to it.

    # detect if we're in a PASE shell
    /QSYS.LIB/QSHELL.LIB/UNAME.PGM > /dev/null 2>&1
    
    if [ $? != 0 -a "$SHELL" != "/QOpenSys/usr/bin/bash" ]
    then
      exec /QOpenSys/usr/bin/bash
    fi
    

    The .profile file will be processed when a shell session is started and place you into a bash shell. The reference to /QOpenSys/usr/bin/bash is actually a symbolic link that points at /PowerRuby/oss/bin/bash.

    If you don’t want to change sshd_config or write a script for .profile there is still the manual way of entering into bash by typing /PowerRuby/oss/bin/bash in your current SSH session. Note that by doing this you are actually creating a second IBM i job, one for each shell session. To exit the second shell session you can type “exit” and then you will be placed into the initial shell session. Typing “exit” again will log you out of the IBM i shell session.

    Increasing Shell Session Timeout

    It can be frustrating to have your 5250 telnet sessions timeout, and the same is true for SSH sessions. You can address this by modifying the same sshd_config file:

    /QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-4.7p1/etc/sshd_config
    

    Search for ClientAliveInterval, remove the pound comment operator (‘#’), and change the setting equal to the number of seconds you’d like your shell to be open until it automatically closes due to no usage. For example, set your system to the following to have a timeout of 30 minutes:

    ClientAliveInterval 1800
    

    After making changes to the sshd_config file you need to restart the SSH server daemon with the following commands:

    ENDTCPSVR SERVER(*SSHD)
    STRTCPSVR SERVER(*SSHD)
    

    That concludes this tutorial on using PASE, SSH, and bash on your IBM i. For a variety of more info on PASE related things you can check out the YiPs (Young i Professionals) wiki. The YiPs wiki is actually very active and new content is frequently being added and changed.

    Aaron Bartell is a Rubyist at heart, though it wasn’t always that way. Going back more than a decade has Aaron loving RPG and Java as they were the primary means of creating mobile or website solutions on IBM i. That all changed when he was introduced to the Ruby language and Rails web framework because it became very apparent how much time and effort could be saved to produce excellent applications. Ruby on i is now a reality with PowerRuby, so what are you waiting for!? Aaron lives with his wife and five children in southern Minnesota. He enjoys the vast amounts of laughter having a young family brings, along with camping and music. 

     

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Midrange Dynamics North America

    With MDRapid, you can drastically reduce application downtime from hours to minutes. Deploying database changes quickly, even for multi-million and multi-billion record files, MDRapid is easy to integrate into day-to-day operations, allowing change and innovation to be continuous while reducing major business risks.

    Learn more.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Profound Logic Software:  October 1 Webinar: "See What i Can Do with Mobile Applications" System i Developer:  Upgrade your skills at the RPG & DB2 Summit in Minneapolis, Sept 30 - Oct 2. BCD:  Free Webinar: Self-Serve Business Intelligence for IBM i. September 18

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    IBM Broadens European Power Systems ISV Promotion IBM i Modernization Gets A Fresche-look

    2 thoughts on “Bash Is Not A Shell Game”

    • glenngundy says:
      October 25, 2017 at 4:16 pm

      Is it just me or are there missing objects from this page? I see large empty boxes that I’m guessing are pictures of code or screens.

      Reply
    • papatholt says:
      January 11, 2018 at 7:50 am

      Thanks, Glenn. We have added them. If you find other articles for which figures are missing, please let me know at the itjungle.com contacts page.

      Reply

    Leave a Reply Cancel reply

Volume 14, Number 21 -- September 17, 2014
THIS ISSUE SPONSORED BY:

Robot
WorksRight Software
Bug Busters Software Engineering

Table of Contents

  • Bash Is Not A Shell Game
  • Share And Share Alike With RSE
  • Restoring Passwords & Private Authorities When Using RSTUSRPRF

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle