None

Dealing with microfocus sequential files in linux shell


Copy a microfocus enterprise server dataset, edit it and return it back to the server.

By Kostas Koutsogiannopoulos

Using linux shell and all its powerfull tools in order to deal with microfocus sequential files living in a remote linux server is the subject of this post.
The steps we need to open such a file in linux are:

  1. scp to local machine

  2. recode from EBCDIC to ASCII

  3. add new line characters (LF)

  4. view or edit

To save the file back to the server (after edit) we do:

  1. add blanks at the end of each line

  2. truncate new line characters

  3. recode from ASCII to EBCDIC

  4. scp to remote server

The following sample script (name it mf) does the job using identity key for non interactive ssh logins. Encoding is IBM-875 (EBCDIC-Greek) remotely and ISO-8859-7 (ASCII-Greek) localy.

 mf

#!/bin/bash
HOST=mfserver
KEY=~/.ssh/id_rsa_mfserver
DATAPATH=/mrh/prod/data/
LOCALTMP=/home/oper1/shit
USER=mfadmin
COMMAND=$1
INPUTFILE=$2
RLENGTH=$3
export LC_ALL=el_GR.ISO-8859-7
if [ $COMMAND = "vi" ]
then
   ssh -i $KEY $USER@$HOST "cat $DATAPATH$INPUTFILE.DAT" | recode EBCDIC-Greek..ISO-8859-7 > $INPUTFILE
   fold -w $RLENGTH $INPUTFILE > $INPUTFILE.TMP
   $COMMAND $INPUTFILE.TMP
   awk 'length <= '$RLENGTH' { printf "%-'$RLENGTH's\n",$0 }' $INPUTFILE.TMP > $INPUTFILE.TMP1
   tr -d '\n' < $INPUTFILE.TMP1 > $INPUTFILE
   recode ISO-8859-7..EBCDIC-Greek $INPUTFILE
   scp -q -i $KEY ./$INPUTFILE $USER@$HOST:$DATAPATH$INPUTFILE.DAT
   rm $INPUTFILE.*
   exit
elif [ $COMMAND = "savecat" ]
then
   dos2unix -q $INPUTFILE
   awk 'length <= '$RLENGTH' { printf "%-'$RLENGTH's\n",$0 }' $INPUTFILE > $INPUTFILE.TMP1
   tr -d '\n' < $INPUTFILE.TMP1 > $INPUTFILE.TMP2
   recode ISO-8859-7..EBCDIC-Greek $INPUTFILE.TMP2
   scp -q -i $KEY ./$INPUTFILE.TMP2 $USER@$HOST:$DATAPATH$INPUTFILE.DAT
   rm $INPUTFILE.TMP?
   cat > $LOCALTMP/CATALOG.JCL <<CATALOGJCL
//CATJOB JOB MFCAT CLASS=L LINUX JOB
//CATALOG EXEC PGM=MFJBR14
//D1 DD DISP=(,CATLG),RECFM=F,DSORG=PS,LRECL=$RLENGTH,
// DSN=$INPUTFILE
CATALOGJCL
   export MFBSI_DIR=/mrh/mfbsi/PROD
   . $COBDIR/bin/cobsetenv
   mfbsijcl -j"$LOCALTMP/CATALOG.JCL"
   rm $LOCALTMP/CATALOG.JCL
   exit
elif [ $COMMAND = "save" ]
then
   dos2unix -q $INPUTFILE
   awk 'length <= '$RLENGTH' { printf "%-'$RLENGTH's\n",$0 }' $INPUTFILE > $INPUTFILE.TMP1
   tr -d '\n' < $INPUTFILE.TMP1 > $INPUTFILE.TMP2
   recode ISO-8859-7..EBCDIC-Greek $INPUTFILE.TMP2
   scp -q -i $KEY ./$INPUTFILE.TMP2 $USER@$HOST:$DATAPATH$INPUTFILE.DAT
   rm $INPUTFILE.TMP?
   exit
elif [ $COMMAND = "get" ]
then
   ssh -i $KEY $USER@$HOST "cat $DATAPATH$INPUTFILE.DAT" | recode EBCDIC-Greek..ISO-8859-7 > $INPUTFILE.TMP
   fold -w $RLENGTH $INPUTFILE.TMP > ./$INPUTFILE
   rm $INPUTFILE.TMP
else
   ssh -i $KEY $USER@$HOST "cat $DATAPATH$INPUTFILE.DAT" | recode EBCDIC-Greek..ISO-8859-7 > $INPUTFILE
   fold -w $RLENGTH $INPUTFILE | $COMMAND
   echo
   rm $INPUTFILE
fi
exit 0

Usage

$~ mf <linux/custom command> <microfocus dataset name> <record length>

The "to-do list" contains the functionality to get the file's record length from catalog automaticaly. We are planning to publish this in a future post.


View epilis's profile on LinkedIn Visit us on facebook X epilis rss feed: Latest articles