None

Migrating Mainframe's e-mail functionality


An example of getting an xmitip sysin and create a linux mail command.

By Kostas Koutsogiannopoulos

XMITIP was used widely in IBM mainframes in order to add to JCL the functionality to send e-mails.
Using on XMITIP commands you could send informational e-mails to users about the job status or provide them with z/OS files as attachments.
A big-old company may have accumulated hundrends of jobs like that needed to run on a linux machine under microfocus enterprise server. 

First of all we need a cobol program to write the xmitip system input to a temporary file (lets say xmitip_timestamp.txt) and then run a
linux command like the following, getting the return code:

cat xmitip_timestamp.txt | kkmailer.sh

We may name the temporary file using jobid from enterprise server environment in order to avoid possible conflicts with another job running at the same time.

The kmailer.sh script reads line by line the xmitip sysin writen to the file, and uses regular expressions to get the following parameters:

  • Files to attach
  • Filenames for file attachments
  • Sender's mail address
  • Recipients's mail addresses
  • Subject

In this example we are using a standard mail body text for all jobs - "Batch Message".
The parameters are assigned to variables used at the mail command in the end.
Αt the end the linux mail command is executed.

 kkmailer.sh

#!/bin/bash
TMPDIR=/tmp/kkmailer
while read -r Line; do
String="$String\n$Line"
done
function str_str {
    local str
    str="${1#*${2}}"
    str="${str%%$3*}"
    echo -ne "$str"
}
if [[ $String =~ .*FILE\ .* ]]
then
FILES=(`str_str "$String" "FILE" "FILENAME" | grep -E -o "[a-zA-Z#$@][a-zA-Z0-9#$@-]{0,7}([.][a-zA-Z#$@][a-zA-Z0-9#$@-]{0,7}){0,21}"`)
FILENAMES=(`str_str "$String" "FILENAME" "SUBJECT" | grep -E -o "([A-Z]|[a-z]|[0-9]|_|-|\.|)+\.(txt|TXT|csv|CSV|xls|XLS|apa|csi|CSI|cso|CSO|ati|ATI|dat|DAT)"`)
#Convert the files
for (( i=0; i<${#FILES[@]}; i++ )) do
/home/mfadm22/bin/mf getas ${FILES[i]} $TMPDIR/${FILENAMES[i]}
done
fi
SUBJECT=`echo -n $String | grep -E -o "SUBJECT .*" | sed "s/SUBJECT //g" | sed "s/'//g" | tr -dc '[[:print:]]' | sed "s/+//g" | sed "s/ NOMSG//g"`
FROM=`echo -e $String | grep FROM | grep -E -o "\b+[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b"`
TO=`echo -e $String | grep -v FROM | grep -E -o "\b+[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b"`
#Create mail command
MAILCOMMAND=$(echo "echo \"Batch Message\" | /usr/bin/mail -s \"$SUBJECT\" -r \"$FROM\" `for (( i=0; i<${#FILES[@]}; i++ )) do echo -n " -a \"$TMPDIR/${FILENAMES[i]}\""; done` `echo -n $TO | sed "s/ /,/g"`")
echo $MAILCOMMAND | bash

As we see, a routine is executed for every file needed to sent by attachment:

~$ mf getas ${FILES[i]} $TMPDIR/${FILENAMES[i]}

As we described in that  every file in order to be "pc readable" must be ASCII and completed with new line characters at the end of every record. In order get the record length and the encoding of the file, we used the microfocus esmac interface. So we developed the mf script of the old post to make the suitable conversions depending on the file specs.

The new mf script:

 mf

#!/bin/sh
HOST=mfserver
KEY=~/.ssh/id_rsa_mfserver
DATAPATH=/mrh/prod/data/
LOCALTMP=/home/oper1/shit
USER=mfadmin
COMMAND=$1
INPUTFILE=$2
RLENGTH=$(expr `curl -s "http://$HOST:5003/esmac/casrdo46?entName=$INPUTFILE&" | grep Lrecl | awk -F\" '{print $(NF-3)}'` + 0)
echo $RLENGTH
ENCODING=`curl -s "http://$HOST:5003/esmac/casrdo46?entName=$INPUTFILE&" | grep -e 'selected .* value.*EBCDIC' | awk -F\" '{print $(NF-1)}'`
export LC_ALL=el_GR.ISO-8859-7
if [ $COMMAND = "getas" ]
then
   if [ "$ENCODING" == "E" ]
   then
   cat $DATAPATH$INPUTFILE.DAT | recode EBCDIC-Greek..ISO-8859-7 | fold -b -w $RLENGTH | sed 's/[ \t]*$//' | sed 's/$/\r/' > $3
   echo -e '\n' >> $3
   else
   cat $DATAPATH$INPUTFILE.DAT | fold -w $RLENGTH | sed 's/[ \t]*$//' | sed 's/$'"/`echo \\\r`/" > $3
   fi
else
   exit 16
fi
exit 0

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