Python: DCL Conversion to Python

  1. Introduction to Python
  2. Python: Choosing a Text Editor or IDE
  3. Python: Hello World
  4. Python: Variables, Strings and Numbers
  5. Python: Variable Naming
  6. Python: Math, Familiar
  7. Python: Math, Less Familiar
  8. Python: Mathematical Order of Operations
  9. Python: Introducing PEP 8
  10. Python: Text Concatenation
  11. Python: if Statements and Comparison Operators
  12. Python: else and elif statements
  13. Python: Testing Multiple Conditions
  14. Python: Testing Sets of Conditions
  15. Python: Nested if Statements
  16. Python: Lists
  17. Python: Adding To and Changing Lists
  18. Python: Lists: Take a Slice, Delete Elements, Popping Elements
  19. Python: Tuples
  20. Python: for Loops
  21. Python: Nested for Loops
  22. Python: Capturing and Formatting User Input
  23. Python: Dictionaries
  24. Python: Functions
  25. Python: While Loops
  26. Python: Data Files
  27. Python: Using Pexpect
  28. Python : Using Pexpect : ftpTestOffload.sh
  29. Python : Using Pexpect: ftpTest.py
  30. Python: DCL Conversion to Python

This script is specific to operations moving from VMS to Linux, which requires migrating DCL scripts to Python scripts.

 

#!/bin/bash

# processDCL.sh

# Glenn Norman 2018

# Uncomment these two lines to prompt for a script name.
# This script assumes the DCL script is a plain text file.
# echo "Please specify a DCL script: "
# read filename

# Uncomment the line below to run in debug
# (automatic file selection) mode.
filename=DBMS_OOS_MEDICAID_RPT_POSTED.txt
echo 1

# Remove unused head and tail material from a DCL script
if [ -e $filename ]; then
echo 2
# trim off the head matter
awk '/CSESSION/,0' $filename > file1
echo 3
# trim off the trailing matter
sed '/HALT/q' file1 > file2
echo 4

else
echo "Please enter a valid file name."
echo 5
fi

echo 6

# get rid of $!
sed s/\$\!//g file2 > file3
echo 7

# get rid of leading spaces
sed -e 's/^[[:space:]]*//' file3 > file4
echo 8

# prefix every line
sed -e 's/^/xx/' file4 > file5
echo 8.5

# split the lines
sed -e 's/!/\n!/g' file5 > file6
echo 9

# correct the line order
sed 'N;s/\(.*\)\n\(.*\)/\2\n\1/' file6 > file7
echo 10

# remove all spaces from the end of lines
sed -i 's/[ \t]*$//' file7
echo 11

# turn all lines that start with a bang into expect lines
sed s/!/child.expect\(\'/g file7 > file8
echo 12

# now add sendline to all lines that start with xx
sed -e s/xx/child.sendline\(\'/g file8 > file9
echo 13


# add the ') suffix to each line
sed s/$/\'\)/g file9 > file10
echo 15

# fix extra line returns
tr -d '\015' < file10 > file11

# TODO: Transform first line to child = child.spawn ...

# TODO: Add head material: shebang, include and any other 
# necessary lines.

# TODO: Add cleanup routine to delete temp files.

# TODO: Review output file for any further needed transformations.

# TODO: Update final filename to original name + timestamp + .py.