Monthly Archives: July 2015

Useful Shell/SSH/Bash commands for IBMi

What is my current path to binaries and libs:

echo $PATH

add a directory to my path so I don’t have to fully qualify the path to run. (we’re adding /QOpenSys/usr/bin)

export PATH=$PATH:/QOpenSys/usr/bin

Permanently set the default PATH used when you connect.  Create /home/MYPROFILE/.profile and add the export command above

In bsh just use

PATH=$PATH:/QOpenSys/usr/bin

set libpath for *.so files

LIBPATH=$LIBPATH:/QOpenSys/opt/freeware/lib

Useful FTP commands for IBMi

Open connection to i

ftp ibminame

Change file system format from “system mode” (i.e. /Qsys.Lib/Myfile.file/MyMember.mbr ) to “IFS mode” (i.e. /var/www ) to change directories (cd) on the IFS

site NAMEFMT 1

Turn off interactive mode (so you don’t have to say yes to ever FTP upload)

prompt

change to binary mode when uploading files that aren’t text

bin

upload multiple files based on file type.

mput *.{filetype}

What can i do with SSH on IBMi? The alternative to QP2TERM AKA “OMGAwful”

Call SQL on DB2

system -i “call QSYS/QZDFMDB2 parm(‘select * from lib.table’)”

Create an alias in your .bash_profile file so its easier to run the command above

alias db2=’function _db2(){ echo “Running $1”; system -i “call QSYS/QZDFMDB2 parm(‘\”$1’\”)”; };_db2’

the sql command above becomes

db2 ‘select * from lib.table’

you can even send a sql file to this

db2 < cat ‘MyFile.sql’

Search the output of the Select statement via grep

system -i “call QSYS/QZDFMDB2 parm(‘select * from lib.table’)” | grep replace_w/_search_term

View all active jobs

system WRKACTJOB

Search all active jobs by user (case insensitive)

system WRKACTJOB | grep -i username

View all command line utilities that are available to use

ls -l /QOpenSys/usr/bin/  

Create a shell script MyShellScript.sh that executes multiple commands.  Then run it by calling MyShellScript on the ssh commandline.  And theres no need to COMPILE!  like you would need to if this was a CL program.

MyShellScript.sh

#!/QOpenSys/usr/bin/bash
echo “Your running MyShellScript”
system WRKACTJOB | grep -i bob
system WRKACTJOB | grep -i sally

Setting the Path so you don’t have to type the path to your executable.  There’s the 5250 way and the SSH way.  You want to use $PATH to include the current path and then append to it by using a : (colon) as a deliminator.

5250: WRKENVVAR to setup PATH
SSH: Create .profile under /home/USERNAME , or /etc/profile, or environment file
PATH=$PATH:/QOpenSys/opt/freeware/bin/
Or run on the ssl command line: export PATH=$PATH:/QOpenSys/opt/freeware/bin/

View what your PATH and other environment variables are set to on the SSH shell

env

View process statuses (WRKACTJOB)
ps
ps -ef

View Zend Processes

ps -ef | grep -i zend

Find the JobId,User, and program of the process ids

ps -ef | grep -i zend | awk '{print "qsh_out -c '\''/usr/bin/getjobid "$2"'\''"}'

Run git after you install it from http://perzl.org/

Find your CCSID system value and if its on 65535 change your profile to use ccsid 37

system "DSPSYSVAL SYSVAL(QCCSID)"
system "CHGUSRPRF USRPRF(MYPROFILE) CCSID(37)"

Display your library list from QSH or the current shell

qsh -c '/QSYS.LIB/QSHELL.LIB/SYSTEM.PGM dsplibl'
system -i "DSPLIBL"

view a joblog

qsh_out -c "system -i 'dspjoblog job(123456/LIB/PGM)'"

Edit files with various editors (vim, nedit, vi, joe) or setup auto SFTP on a local IDE and upload your files on save to the IBMi

Restart Apache

/usr/local/zendsvr6/bin/i5_apache.sh restart

You may have to run this on the shell if you run into issues with the editor such as

xterm-256color: Unknown terminal type 
[hit return to continue] 
Visual needs addressable cursor or upline capability

or

xterm^M: Unknown terminal type
[Hit return to continue] 
[Using open mode]

You can either run this on the command line or setup your .bash_profile to setup this variable every time you log in

TERM=xterm

You’ll also want to look into setting up your .profile and .bash_profile files which are loaded when you ssh in, and run bash respectively.  These files should be created in the directory /home/MYUSER/

.bash_profile example:

Got any other ideas?  Share in the comments below

References

Tony C. CommonUG April 2015 – http://www.gateway400.org/documents/Gateway400/Handouts/IBMiFunWithShells.pdf

Setting up SSH on IBMi

Installing Bash on IBMi

Other cool things you can do w/ Bash

Quick and Simple way to install Bash on IBMi w/ local files

UPDATE 6.27.2016: If you rather install from a PTF check 5733-OPS opt 7 PTF SI61062 else learn to install it from Perzl’s site

Follow the steps below to install Bash

1. Download and unzip download-2.01-PHPDave.tar.zip locally and upload download-2.01-PHPDave.tar.zip to /QOpenSys on the IBMi

2. Open a 5250 session and run CALL QP2TERM.  We’ll extract the tar.zip file and it will create a download directory that will store all our open source binaries (such as Bash).  In QP2Term shell run:
cd /QOpenSys
tar -xf download-2.01-PHPDave.tar.zip
cd download

3. We’ll execute setup2.sh which installs various utilities needed to run wwwperzl.sh.  In QP2TERM and in directory: /QOpenSys/download run

#give the user, execute permission on setup2.sh
chmod u+x setup2.sh
./setup2.sh

4. Download bash (bash-4.3-16.aix5.1.ppc.rpm) and upload it to /QOpenSys/download/www.oss4aix.org/rpmdb/db

5. Download bash dependencies (bash-4.3-16.aix5.1.ppc.deps) and upload it to /QOpenSys/download/www.oss4aix.org/rpmdb/deplists/aix61

6. We’ll now get bash installed. In QP2TERM and in directory: /QOpenSys/download run

./wwwperzl.sh aix61 rpm1 bash-4.3

7. Bash should now be available!!! at the following directory: /QOpenSys/opt/freeware/bin/bash .  SSH into your ibmi and run /QOpenSys/opt/freeware/bin/bash.   Tips on setting up SSH for IBMi

Notes:

1. view other bash versions here if you want a different version: ftp://www.oss4aix.org/RPMS/bash/

2. view other bash deps here if you want a different version: ftp://www.oss4aix.org/rpmdb/deplists/

3. View this image to determine which aixXX to use when running ./wwwperzl.sh aixXX rpm1 bash-4.3

4. You used to have to Download http://yips.idevcloud.com/wiki/uploads/PASE/setup2.sh and http://yips.idevcloud.com/wiki/uploads/PASE/wwwperzl.sh and upload setup2.sh and wwwperzl.sh to /QOpenSys/download but i’ve included that in the zip file

Reference

http://yips.idevcloud.com/wiki/index.php/PASE/OpenSourceBinaries#perzl

http://www.perzl.org/aix/

Whats in setup2.sh and wwwperzl.sh

Setting up SSH for IBMi #Gotchas

Tired of using CALL QP2TERM and STRQSH and trying to run SSH?  Here’s some tips that may help:

Connect to your IBMi via ssh client

ssh -X username@ibminame

After entering the password to your SSH connection to the IBMi if you get this error:
Permission denied, please try again.

You need to add the following to the end of sshd_config file because there’s an 8 character limit on username and password until this is in the sshd_config file

ibmpaseforienv PASE_USRGRP_LIMITED=N

Note: that if your username is longer than 8 characters it won’t display and instead “I have no name! ” will display

If you have bash installed you can set it as your default shell by adding this to sshd_config (How to setup bash)


ibmpaseforishell=/QOpenSys/opt/freeware/bin/bash
#or uncomment the line below if you want zshell
#ibmpaseforishell=/opt/freeware/bin/zsh

Note: The change above will globally effect all ssh connections. If your using chroot, the chrooted environment will need (/QOpenSys/opt/freeware/bin/bash) in its rooted directory or ssh will fail

Alternatively you can add this to your .profile in the home directory so that bash will automatically be started

if [ $? != 0 -a "$SHELL" != "/QOpenSys/usr/bin/bash" ]
then
exec /usr/bin/bash -login
fi

Setting up SSHD host on IBMi

1. Edit your ssh config and enable “ForwardX11 yes“. You can either edit via FTP, WRKLNK etc..  yes is case sensitive
/QOpenSys/QIBM/UserData/SC1/OpenSSH/openssh-4.7p1/etc/sshd_config

2. End and Start SSH on the IBMi run this command on the 5250. Note: the sshd_config is only loaded once when you start the server, so changes won’t get applied until a restart

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

Ok, i’ve SSH’d into the IBMi  NOW What?  View what you can do w/ SSH on IBMi here!

Add this line to enable SFTP

Subsystem sftp /QOpenSys/QIBM/ProdData/SC1/OpenSSH/openssh-4.7p1/libexec/sftp-server

If you ever get the messages below it’s probably because SSH is not running

Connecting to USERNAME@MYIBMI…
Loading NaCl plugin… done.
ssh: connect to host MYIBMI port 22: Connection refused
NaCl plugin exited with status code 255.

References:

Man Page for SSHD with various settings you can use – https://www.freebsd.org/cgi/man.cgi?query=sshd_config&sektion=5

http://ibmsystemsmag.com/Blogs/i-Can/Archive/pase-twilight-zone-removing-more-myths-about-ibm-i/

https://support.zend.com/hc/en-us/articles/203738046-Studio-failed-to-connect-sshd-on-IBM-i-long-user-ID-or-password

http://yips.idevcloud.com/wiki/index.php/PASE/SSHSetup

Pulling #IBMi Source Members to Stream files to run Git on #RPG/#CL/etc… source code via #CL & #PHP #sourcecontrol

Currently in the proof of concept phase but I think this could be used to convert File Members to stream files so they could be used to check into a git repository.

Changes to the source file will hopefully kick off the trigger, which will then call CL program to call the PHP script to pull down all the file’s members into stream files.  Then its in the developer’s hand to run git on the files.  I’ve also considered creating an automated job that would auto-commit an auto-update the git repo so the code would always be checked in and know one would need to do the commits and updates.

difference between PC file structures and AS400/IBMi Difference between PC file structures and AS400/IBMi

New downlaod for #IBMi Access Client Solutions released. (Data transfer, 5250)

IBM just released a new Access Solutions IBMiAccess_v1r1m4_Update2.zip on July 16!

1. You can download it here:

ftp://public.dhe.ibm.com/as400/products/clientaccess/solutions/updates/

2. unzip it

3. run the script in the corresponding OS folder (Linux_Application,Mac_Application,Windows_Application)

4. click the desktop shortcut or use the hotkeys CTRL+ALT+SHIFT+A, CTRL+ALT+SHIFT+B