contact image

Qshell

Qshell is a command environment based on POSIX and X/Open standards. It consists of two parts:

  1. The shell interpreter (or qsh) is a program that reads commands from an input source, interprets each command, and then runs the command using the services of the operating system.
  2. The utilities (or commands) are external programs that provide additional functions and can be quite simple or very complex.




Change the date and time of all objects in a folder on the IFS.


Sample from Jamie Flanary posted at 2011-12-12 18:27:28

STRQSH CMD('touch  -t  200712250000.00 /home/flanary/test.doc')  

A much easier way to zip *ALL documents in one folder on the IFS.


Sample from Jamie Flanary posted at 2011-12-12 18:15:04

I have 4 .csv files created in QTEMP
I need to email these to the user that
just created them....

created folder on root called ZIP
(this works fine for me cause Im the only one doing this)
You will need to create subfolders by job to release this
to the hounds.
PHP Code:
MD DIR(zip) DTAAUT(*RWX) OBJAUT(*ALL)  

In my case I just ran 4 cpytoimpf commands


PHP Code:
CPYTOIMPF FROMFILE(QTEMP/WKR20WORK1) TOSTMF('zip/wkr20work1.csv')
STMFCODPAG(*PCASCII) RCDDLM(*CRLF)      

CPYTOIMPF FROMFILE(QTEMP/WKR20WORK2) TOSTMF('zip/wkr20work2.csv')
STMFCODPAG(*PCASCII) RCDDLM(*CRLF)      

CPYTOIMPF FROMFILE(QTEMP/WKR20WORK3) TOSTMF('zip/wkr20work3.csv')
STMFCODPAG(*PCASCII) RCDDLM(*CRLF)      

CPYTOIMPF FROMFILE(QTEMP/WKR20WORK4) TOSTMF('zip/wkr20work4.csv')
STMFCODPAG(*PCASCII) RCDDLM(*CRLF)  


Then to get them to the zip file......named profit.zip

PHP Code:
STRQSH CMD('jar cfM zip/profit.zip zip/*.*')  

*** Note dont run this I think it would zip the entire IFS into a zip file
that can never turn out GOOD! 

PHP Code:
STRQSH CMD('jar cfM zip/profit.zip *.*')  

anyway then you have your files all zipped up and
can send them to anyone you wish with your favorite 
email process. (there are a couple posted on the site)

Using QSHELL to zip and unzip objects in the IFS


Sample from Jamie Flanary posted at 2011-12-12 18:04:00

Here are the steps to add the Unzip and Zip functions to your System i server: 
Go to the following File Transfer Protocol (FTP) site and download the archives:

http://www.ctan.org/tex-archive/tool...-zip/UNIX/AIX/
In our case, we download these files:

zip23x-aix43.zip To compress (zip) files
unz550x-aix5L.tar.gz To uncompress (unzip) files
Place these files somewhere on your System i server. In this example, we use /home/zip. 
You will also need the gunzip tool to uncompress the unz550x-aix5L.tar.gz file. Download the tool from the following Web site:
http://www-03.ibm.com/servers/enable...utilities.html

Place the file in the same directory as the other two files.
Review the license agreement for the downloaded tools.
Sign on to your System i server and start an i5/OS PASE terminal with the command:


CALL QP2TERM

Change to the /home/zip directory:



cd /home/zip

The unzip file is a compressed file. Uncompress this file:



uncompress gzip.1.2.4a.tar.Z

Untar” the gzip tar file:



tar -xvf gzip.1.2.4a.tar

It installs the executable files under the /usr/local/bin directory.


Update the PATH variable with the /usr/loca/bin directory by running this command:


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

Uncompress the unz550x-aix5L.tar.gz file using this command:



gunzip unz550x-aix5L.tar.gz

“Untar” the uncompressed file:



tar -xvf unz550x-aix5L.tar

It creates the directory unzip-5.50.
Change to this directory:



cd unzip-5.50

Enter the following command:



 unzip

It shows you the command usage text.


To run the command from any directory and any terminal window, you have to copy the unzip file into the /QOpenSys/usr/bin directory: 


cp unzip /QOpenSys/usr/bin


Switch back to the directory to which you have downloaded the files:



cd /home/zip


Now check whether unzip is really working. The Zip program on our system is packed in the zip file - zip23x-aix43.zip, so we can try on that one. Verify that you are in the directory in which the zip23x-aix43.zip file is located. Enter the following command:


unzip -d ./zip zip23x-aix43.zip


This creates a directory named zip and places all files into that directory. Change to this directory:


cd zip


Issue the following command to see if the program is working:

 zip
 

This will show the usage notes.
To make the command available in every i5/OS PASE terminal session, copy the program into the /QOpenSys/usr/bin directory.


  cp zip /QOpenSys/usr/bin
  

To use both commands (zip and unzip) in QShell, make another copy of the programs into the /usr/bin directory by running 2 commands:


cp /QOpenSys/usr/bin/zip /usr/bin 
cp /QOpenSys/usr/bin/unzip /usr/bin


Now zip and unzip are available for the next QShell terminal.

Changing CCSID of IFS table


Sample from Scott Klement posted at 2011-12-11 10:45:27

Another way to do the same thing is with the SETCCSID command in QShell. 
Here's an example of that command:

STRQSH CMD('setccsid 819 /path/to/myfile.txt')
If the data in the stream file also needs to be converted, you can use QShell's 
ICONV command to convert it. This does not set the CCSID of the resulting file 
properly, but we already know how to fix that!

The following command converts the data in MYFILE.TXT from 
CCSID 37 to CCSID 819 and writes the output to YOURFILE.TXT:

STRQSH CMD('iconv -f 37 -t 819 /path/to/myfile.txt > /path/to/yourfile.txt 
&& setccsid 819 /path/to/yourfile.txt')

program reads STDIN and translates all of the * spaces to periods


Sample from Scott Klement posted at 2011-12-11 10:41:17

     * This rather silly program reads STDIN and translates all of the
      * spaces to periods, then writes it to STDOUT.
      *
      * You need to run this from QSHELL for it to be useful:
      *          /qsys.lib/yourlib.lib/this.pgm

     H BNDDIR('QC2LE') DFTACTGRP(*NO)

     D read            PR            10I 0 extproc('read')
     D  fd                           10I 0 value
     D  buf                            *   value
     D  len                          10I 0 value

     D write           PR            10I 0 extproc('write')
     D  fd                           10I 0 value
     D  buf                            *   value
     D  size                         10I 0 value

     D data            S             80A
     D len             S             10I 0

     c                   eval      len = read(0: %addr(data): %size(data))
     c                   dow       len > 0
     c     ' ':'.'       xlate     data          data
     c                   callp     write(1: %addr(data): len)
     c                   eval      len = read(0: %addr(data): %size(data))
     c                   enddo

     c                   eval      *inlr = *on


To run this, you need to run it from QSHELL.  Here's how I did it:

1) Type STRQSH

2) At the QSHELL prompt, I typed:

echo "I sure wish I had periods in this text!" | /qsys.lib/mylib.lib/test.pgm

(that should all be one line, if it gets wrapped)


And the result looked like this:

   I.sure.wish.I.had.periods.in.this.text!

CL Program using Shell command ls to dump directory listing to a file


Sample from Jamie Flanary posted at 2011-12-11 10:33:11

PGM                                                         
                                                            
CD         DIR('/myxml/data')                               
CRTPF      FILE($library/ifsdir) RCDLEN(128)                     
STRQSH     CMD('ls -lt *.* > +                              
             /qsys.lib/$library.lib/ifsdir.file/ifsdir.mbr')     
                                                            
ENDPGM