Created
September 17, 2020 20:34
-
-
Save mainframed/fb2389fb9c3696a1ba7fbb0cb3cfb0cd to your computer and use it in GitHub Desktop.
Use rdrprep and recv370 to extract XMI files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#A files with XMI header? | |
TEMP=$1 | |
XMIT=$2 | |
if [ $# -eq 0 ] | |
then | |
echo "[!] Temp dataset argument for XMIT extract required" | |
echo "Usage: ./$0 TEMP.DATASET.PDS" | |
exit 1 | |
fi | |
PRINTER='../../tk4-test/prt/prt00e.txt' | |
SLEEP=5 | |
function sendjob { | |
echo "[+] sj :: Creating JCL for $XMIT to $TEMP" | |
cat << THE_BIG_JOB > out.jcl | |
//UNXMIT20 JOB CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1), | |
// USER=HERC01,PASSWORD=CUL8TR | |
//DELETE EXEC PGM=IDCAMS,REGION=1024K | |
//SYSPRINT DD SYSOUT=A | |
//SYSIN DD * | |
DELETE $TEMP NONVSAM SCRATCH PURGE | |
/* IF THERE WAS NO DATASET TO DELETE, RESET CC */ | |
IF LASTCC = 8 THEN | |
DO | |
SET LASTCC = 0 | |
SET MAXCC = 0 | |
END | |
/* | |
//RECV370 EXEC PGM=RECV370,REGION=4096K | |
//RECVLOG DD SYSOUT=* | |
//XMITIN DD DATA,DLM=\$\$ | |
::E $XMIT | |
\$\$ | |
//SYSPRINT DD SYSOUT=* | |
//SYSUT1 DD DSN=&&SYSUT1, | |
// UNIT=3390, | |
// SPACE=(TRK,(250,250)), | |
// DISP=(NEW,DELETE,DELETE) | |
//SYSUT2 DD DSN=$TEMP, | |
// UNIT=3390, | |
// SPACE=(TRK,(250,250,25),RLSE), | |
// DISP=(NEW,CATLG,DELETE) | |
//SYSIN DD DUMMY | |
//LISTDS EXEC PGM=IKJEFT01 | |
//SYSTSPRT DD SYSOUT=* | |
//SYSTSIN DD * | |
LISTDS $TEMP MEMBERS | |
/* | |
// | |
THE_BIG_JOB | |
echo "[+] sj :: Translating to EBCDIC" | |
rdrprep out.jcl | |
echo "[+] sj :: Sending to localhost:3505" | |
nc -w 1 localhost 3505 < reader.jcl | |
echo "[+] sj :: sleeping $SLEEP" | |
sleep $SLEEP | |
echo "[+] sj :: Cleaning up" | |
rm reader.jcl | |
rm out.jcl | |
} | |
function getfiles { | |
J=$(grep UNXMIT20 $PRINTER|tail -1|awk '{print $4}') | |
JOBNUM=$(printf "%4s" "$J") | |
echo "[+] gf :: Got jobnum: $JOBNUM" | |
echo "[+] gf :: Members:" | |
sed -n "/A START JOB $JOBNUM/,/A END JOB $JOBNUM/{/--MEMBERS--/,/^END/p}" $PRINTER|tail +2|head -n -1 | |
for i in `sed -n "/A START JOB $JOBNUM/,/A END JOB $JOBNUM/{/--MEMBERS--/,/^END/p}" $PRINTER|tail +2|head -n -1`; do | |
echo "[+] gf :: Downloading $TEMP($i) [binary]" | |
wget -P $folder_path ftp://herc01:cul8tr@localhost:21021/$TEMP/$i | |
echo "[+] gf :: Downloading $TEMP($i) [ascii]" | |
wget -P $folder_path/ascii "ftp://herc01:cul8tr@localhost:21021/$TEMP/$i;type=ascii" | |
done | |
} | |
while grep -anorb $'\xc9\xd5\xd4\xd9\xf0\xf1' ./|grep -aq ":1:2:" ; do | |
for f in `grep -anorb $'\xc9\xd5\xd4\xd9\xf0\xf1' ./|grep -a ":1:2:"|awk -F: '{print $1}'`; do | |
echo "[+] Found ${f:2}" | |
path_to_file=${f:2} | |
folder_path=$path_to_file.out | |
filename=`basename $f` | |
full_path=$folder_path/$filename | |
if ((${#full_path} > 75)); then | |
echo "[!] XMIT Filepath too long for rdrprep (maxlen 75) :(" | |
echo "[!] Filename: $f $file" | |
echo "[!] Fullpath: $full_path" | |
echo "[!] length: ${#full_path}" | |
exit 1 | |
else | |
echo "[+] Making folder $folder_path" | |
mkdir -p $folder_path | |
mkdir -p $folder_path/ascii | |
echo "[+] Moving $path_to_file to $folder_path/$filename" | |
mv $path_to_file $folder_path/$filename | |
echo "[+] processing $folder_path/$filename" | |
XMIT=$folder_path/$filename | |
sendjob | |
getfiles | |
echo "[+] Removing $folder_path/$filename" | |
rm $folder_path/$filename | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment