StarQuest Technical Documents

How to Create a Shell Script with CASH

Last Update: September 9, 1998
Product: Client Access for UNIX
Operating System: All
Article ID: SQV00CA006

Abstract

Client Access for UNIX OS comes with the command line utility cash. You can choose to script this application to execute repetitive tasks. This document will show three ways to automate cash.

Solution

This document describes three methods for creating a shell script that uses the cash utility.

  • A text file with cash commands can be redirected into cash. For example:

    cash < input_file

The output can also be printed on the screen, as well as to an output file, by using the following command:

cash < input_file 2>&1 | tee ${OUTFILE}

The contents of the input file may look like this:

get /qsys.lib/tim.lib/myfile.file /home/tim/myfile
put myfile /qsys.lib/tim.lib/yourfile.file
mkdir /temp

  • Another way to script it would to create the following script, and call it run_cash:

    echo Executing cash command $*
    $CA400/bin/cash << EOF
    $*
    EOF
    echo status is $?

Then, you can call this script on the command line with a single cash command, such as:

run_cash get /qsys.lib/tim.lib/myfile.file myfile

  • You can do this without having to create any files, and calling it on a single command line.

    echo 'command' | cash

e.g.

echo 'get /qsys.lib/tim.lib/myfile.file myfile' | cash

This would be the simplest and most powerful way to script cash.

Invoking the Script

You can invoke the script from the AS/400 computer by using the RUNRMTCMD command:

RUNRMTCMD CMD('/home/mydir/myscript') RMTLOCNAME(MYUNIX *IP) RMTUSER('myuser') RMTPWD('mypassword')

Be sure to enclose the user and password in single quotes to prevent the AS/400 CL interpreter from folding them to upper case. Output from the script will appear in the AS/400 printer queue (e.g. PRT01).

The inetd daemon on the UNIX system needs to be configured to allow incoming rexec requests.

On most UNIX systems, this is done by editing /etc/inetd.conf e.g.:

exec stream tcp nowait root /usr/sbin/rexecd rexecd

and sending a SIGHUP signal to the running inetd process with

kill -HUP processID

On Linux systems, enable rexec by editing /etc/xinetd.d/rexec (change disable from yes to no) and invoking

/etc/init.d/xinetd reload

 


DISCLAIMER

The information in technical documents comes without any warranty or applicability for a specific purpose. The author(s) or distributor(s) will not accept responsibility for any damage incurred directly or indirectly through use of the information contained in these documents. The instructions may need to be modified to be appropriate for the hardware and software that has been installed and configured within a particular organization.  The information in technical documents should be considered only as an example and may include information from various sources, including IBM, Microsoft, and other organizations.