Solved

VAX DCL code to UNIX bash shell script conversion

Posted on 2012-03-20
11
1,000 Views
Last Modified: 2012-03-22
I am trying to convert VAX DCL code (FILE.COM) to UNIX shell script file and I am not even sure where to start? I already got an advice from Unix expert that Unix does not use logicals as VAX DCL, so how can this code be rewriten or converted to Unix shell script with the exact same features? Any help will be greatly appreciated!!

Note: this VAX DCL (FILE.COM) code is runing fine and with no problems on VAX machine. When FILE.COM runs from the command line in VAX, it executes SASprogram2.SAS (Module1) program.
 

$!--------------------FILE.COM-----------------------
$!-----------------------------------------------------------------------------
$! Date and Time configuration
$!-----------------------------------------------------------------------------
$  datetime = f$time()
$  DATESTAMP = F$EXTRACT(0,11,DATETIME)
$  TIMESTAMP = F$EXTRACT(12,8,DATETIME)
$!--------------------------------------------------------------------------
$! Set and create global variables, define file name logicals 
$!--------------------------------------------------------------------------
$  PROCSTAT == 9
$  MAILSUBJ == ""
$! -------------------------------------------------------------  
$! DEFINE LOGICAL                                        
$! ----------------------------------------------------------   
$  DEFINE/NOLOG   logical1   mydir1:SASdataset1.SAS7BDAT
$  DEFINE/NOLOG   logical2   mydir2:status.LIS
$  DEFINE/NOLOG   logical3   mydir2:SASprogram1.LOG
$  DEFINE/NOLOG   logical4   mydir3:MAIL.TXT
$  DEFINE/NOLOG   logical5   mydir2:SASprogram2.LOG
$!---------------------------------------------------------------------------
$! Execute, search for errors in SAS log
$!---------------------------------------------------------------------------
$ set noon
$ sas/sortpgm=best/sortsize=0/log=logical5/print=logical5  mydir3:SASprogram2
$ on error then continue
$  search/nowarnings/nooutput  logical5 ERROR
$  if $status .EQS. "%X00000001"  !-- Error found in SAS code
$  then
$    say "*** PROCESS Module1:  SASprogram2.SAS ==> FAILED - check log ***"
$    wait 00:00:03
$    mailsubj == "ERROR: SASprogram2, REVIEW SAS LOG"
$    OPEN/APPEND LOGF logical3
$    WRITE LOGF "******************************************************"
$    WRITE LOGF "* Module 1"
$    WRITE LOGF "* Date:’’DATESTAMP’   Time:’’TIMESTAMP’ "
$    WRITE LOGF "* ERR msg: Module1 failed => review SAS log"
$    WRITE LOGF "*******************************************************"
$    CLOSE LOGF 
$    mail/subject="''MAILSUBJ'" NL: "@MAIL"
$    PROCSTAT == 1
$    goto endprocss
$   else
$      if PROCSTAT .NE. 0   
$      then
$         say "*** PROCESS Model1: SASprogram2.SAS ==> FAILED => check log ***"
$         wait 00:00:03
$         mailsubj == "ERROR: Module1-FAILED, PROCSTAT <> 0"
$         OPEN/APPEND LOGF logical3
$         WRITE LOGF "******************************************************"
$         WRITE LOGF "* Module1"
$         WRITE LOGF "* Date:''DATESTAMP'   Time:''TIMESTAMP' "
$         WRITE LOGF "* ERR msg: Module1 failed PROCSTAT <> 0"
$         WRITE LOGF "*******************************************************"
$         CLOSE LOGF
$         mail/subject="''MAILSUBJ'" NL: "@MAIL"
$         goto endprocss
$      ELSE
$        SAY "---Module1  ==> Successful"
$         wait 00:00:03
$         mailsubj == "SUCCESSFUL: Module1"
$        OPEN/APPEND LOGF logical3
$         WRITE LOGF "******************************************************"
$         WRITE LOGF "* Module1"
$         WRITE LOGF "* Date:''DATESTAMP'   Time:''TIMESTAMP' "
$         WRITE LOGF "* Msg: Module1 => SUCCESSFUL"
$         WRITE LOGF "*******************************************************"
$         CLOSE LOGF
$         mail/subject="''MAILSUBJ'" NL: "@MAIL"
$    open/read indat file1.dat
$  read_loop:  
$    read/end_of_file=endit indat rcd
$    var1=f$extract(0,2,rcd)
$    if f$search("mydir1:file2.s''var1'") .nes. "" 
$    then  
$      del mydir1:file2.s'var1';* 
$    endif
$!
$    if f$search("mydir1:file3.s''var1'") .nes. ""
$    then 
$      del mydir1:file3.s'var1';*
$    endif
$!
$    if f$search("mydir1:file4.s''var1'") .nes. ""
$    then 
$      del mydir1:file4.s'var1';*
$    endif
$!
$    if f$search("mydir1:file5.s''var1'") .nes. ""
$    then 
$      del mydir1:file5.s'var1';*
$    endif
$!
$  goto read_loop
$       ENDIF
$   ENDIF
$ endit:
$    close indat 
$    del file1.dat;*
$ endprocss:
$    DEASSIGN logical1
$    DEASSIGN logical2
$    DEASSIGN logical3
$    DEASSIGN logical4
$    DEASSIGN logical5
$ exit 

Open in new window

0
Comment
Question by:labradorchik
  • 6
  • 4
11 Comments
 
LVL 10

Expert Comment

by:pfrancois
Comment Utility
As far as I understand, the logicals of VAX DCL seem to be string variables, which obviously also exist in shell scripts.

I suppose you don't expect from us to write a full shell script for you. What you can do is to start coding and when you have a specific question, you ask it to the experts. Don't ask several questions in the same thread, but reward the experts each time one subproblem is solved.
0
 
LVL 47

Expert Comment

by:dlethe
Comment Utility
Eyeballing this DCL, you have some architectural headaches, like invoking mail, and of course, the whole file system is different convention.  

Naming convention is different, and instead of file1.dat;0 & file1.dat;1  for two different revisions of a file, you have just file1.dat   [No trailing ;nnn]

This is too much to ask, at least for me to have somebody write a shell script for you since the O/S itself changes  all the naming conventions, so discussions on that alone, as well as potentially setting up mail / sendmail so mail logs work.

But this is 5-10 mins worth of work for somebody to crank out a shell script that parses a list of files gets parameters, does logging & mail command & spawns the SAS program with parameters.  You will have to tell them directory names, and what flavor of UNIX because mail parameters are not built in as part of bash, so exact syntax is a function of the version of UNIX you are using.

Once a script is written, then there will have to be discussions on naming conventions and how the files must be renamed to be compatible (or vice versa).    Also file naming conventions are different.    If you don't strip off the [ ] : ;x chars from file names then it will break things.

Sorry but a "conversion" isn't possible.  You'll have to look at this as more of a migration / reengineering effort deal with some give & take because some things will be lost in the VMS -> UNIX/POSIX translation.  

To turnkey a conversion is something that you need to expect to pay somebody to do.   Too much work.
0
 

Author Comment

by:labradorchik
Comment Utility
pfrancois thank you very much for your comments!
I wish I could write or convert to Unix bash shell script myself, but I have no idea where to start if logicals are not used in Unix bash shell script the same way as I was using them in VAX DCL?
I really would like someone may be just to start with this Unix bash shell script and I can try to follow your guys examples and finish it up. I also need to figure out how to convert 4 other DCL code programs to UNIX bash shell scripts, so this current conversion will be a great example for me on how to tackle all these convesions.
0
 

Author Comment

by:labradorchik
Comment Utility
WOW, thank you, dlethe!!
I understand that this is a lot of work, but I need to start somewhere.  :)
I see what you mean with different revisions of files. I guess in my example there will be only one or original revision.  

All filenames and directory already given in this DCL program (FILE.COM). As far as Unix flavor, - I have Solaris Unix with Bash shell.

Also, if mail parameters are not built in as part of bash, then I can do without mail function or figure it out later...  My main goal is to run Unix bash shell script with .SAS program in it and hopefully to get the same outcome as I did in VAX DCL.
0
 

Author Comment

by:labradorchik
Comment Utility
Any other Unix bash shell script/VAX DCL experts would like to comment or give any other advices on the conversion of this VAX DCL code (FILE.COM) to Unix Bash shell script?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 47

Accepted Solution

by:
dlethe earned 500 total points
Comment Utility
I have full confidence that you could crank this out if you picked up a bash shell programming book and spent an afternoon with it.    But here is some pseudocode to get you going

DATETIMESTAMP=`date`  # the date command output gets saved in $DATETIMESTAMP (add parameters to date to get mdy, or any other format
DATESTAMP=$DATETIMESTAMP( xxxx)  # lots of substring features using $ : and other chars
# but bottom line $DATESTAMP will equal the string you want

FILESTOCRUNCHDIR=/tmp/myscratchdir
LOGDIR=/var/log/directorynamehere
ANOTHERLOGDIR=/put/another/directory/here

# below puts The datestamp is (the actual datestamp) at end of /var/log/directorynamehere/ThisIsTheFile.txt
echo "The datestamp is $DATESTAMP" >> $LOGDIR/ThisIsTheFile.txt


for tfile in $FILESTOCRUNCHDIR
do
    echo The file I am looking at is $tfile   # this goes to screen

# magic goes here where you open up the file get the bytes you need.  or strings you need, system utilities such as grep, cut, strings, od, hd, and cat can be used but don't know what is best depending on your data

   result0=`the function goes here to crunch $tfile` #answer gets in result0
   if [ "$result0" == "string1" ] ; then
      # do something
   elif [ "$result0" == "string2" ] ; then
      #something else
   else
       echo nothing matched
   fi  # fi ends it

done  #this finishes up loop.
0
 

Author Comment

by:labradorchik
Comment Utility
dlethe, thank you very much for your advices and comments!!!
Below I tried to rewire my DCL code in the Unix bash shell script, could you please see where I might have some problems?

Note: I dopped the mail portion of the program

$#-----------------------------------------------------------------------------
$# Date and Time configuration
$#-----------------------------------------------------------------------------
$ DATETIMESTAMP=`date`     # the date command output gets saved in $DATETIMESTAMP, add             parameters to date to get mdy, or any other format

$ DATESTAMP=$DATETIMESTAMP(12,8,DATETIME)  
                                              # lots of substring features using $ : and other chars
                                              # but bottom line $DATESTAMP will equal the string you want
$ PROCSTAT = 9                     #set and create global variable
$# -------------------------------------------------------------  
$# DEFINE Unix LOGICAL                                        
$# -------------------------------------------------------------  
$ DATADIR=/main/program/mydir1
$ LOGDIR=/main/program/mydir2
$ MAILDIR=/main/program /mydir3
$# ---------------------------------------------------------------------------
$# Execute and search for errors in SAS log
$# ---------------------------------------------------------------------------
$ sas –sysin <$DATADIR/sasprogram2.sas;1> sasprogram2.log;1 
$ search $DATADIR/sasprogram2.log;1  ‘error’
$ if ‘error’ 
$  then
$     echo "  PROCESS Module1:  SASprogram2.SAS ==> FAILED - check log "
$  wait 00:00:03
$     echo “----------------------------------------------------------------“
$     echo “Module1”
$     echo “ Date: $DATESTAMP    Time:  $DATETIMESTAMP”
$     echo “ERR Msg: Module1 failed => review SAS log”
$     echo “----------------------------------------------------------------“
$ PROSTAT=1
$ elif PROCSTAT .NE.  0
$   then
$    echo "  PROCESS Module1:  SASprogram2.SAS ==> FAILED - check log "
$ wait 00:00:03
$     echo “----------------------------------------------------------------“
$     echo “Module1”
$     echo “ Date: $DATESTAMP    Time:  $DATETIMESTAMP”
$     echo “ERR Msg: Module1 failed PROCSTAT <> 0”
$     echo “----------------------------------------------------------------“
$ else
$    echo "SUCCESSFUL:  Module1"
$ wait 00:00:03
$     echo “----------------------------------------------------------------“
$     echo “Module1”
$     echo “ Date: $DATESTAMP    Time:  $DATETIMESTAMP”
$     echo “Msg: Module1  =>  SUCCESSFUL”
$     echo “----------------------------------------------------------------“
$ for file1.dat;1 in $DATADIR
$  do
$      echo $file1.dat;1  
$ result0=`var1(0,2, rcd)`         # is this portion correct? 
$ if  [“$result0”==” $DATADIR/file2.s’var1’;1”] .NES. “ “; then
$ delete $DATADIR/file2.s’var1’;1
$ elif [“$result0”== “$DATADIR/file3.s’var1’;1”] .NES. “ “; then
$ delete $DATADIR/file3.s’var1’;1
$ elif [“$result0”== “$DATADIR/file4.s’var1’;1”] .NES. “ “; then
$ delete $DATADIR/file4.s’var1’;1
$ elif [“$result0”== “$DATADIR/file5.s’var1’;1”] .NES. “ “; then
$ delete $DATADIR/file5.s’var1’;1
$ else
$       echo nothing matched
$ fi
$ done

Open in new window

0
 
LVL 47

Expert Comment

by:dlethe
Comment Utility
Well, this really isn't even close.  The pseudoscript I did was basically to serve as an example of how different the syntax is, but how similar the concepts are.   Enough for you to figure out if you thought you could handle it yourself after spending time with a book in bash programming ... or if you wanted to spend some money with somebody (NOT ME) to do it for you.

My official advice is that you've spent a lot of time on this, and you need to cut your losses.  This is not so much a question for an EE expert on how to do something, you are looking for somebody to write a custom program for you ... for free.

I bet for $100 you would have no problems finding somebody locally to go onsite and crank it out.  This is a little time consuming, but easy.   You really need to just go down that path, unless some other expert comes in and wants to do this for you.
0
 

Author Comment

by:labradorchik
Comment Utility
Thank you for your comments!!
0
 
LVL 47

Expert Comment

by:dlethe
Comment Utility
You are welcome. I hope I didn't ruffle any feathers ;)
Anyway try http://www.guru.com    I've used them many times.  You could post pretty much what you have as-is, with listing.  (after setting yourself up, for free, as an "employer")

Then you let people bid on doing the job, with or without adding a budget.   The great thing is that you pay the $100 to guru.com, and they do 1099 for the contractor, so there are no tax issues, and you put money in escrow.   You don't release until it is working.  You can certainly leave out any budget and let people come back to you.  You might find somebody just say $50.  I don't know.   But guru.com is great site for these one-off projects.
0
 

Author Comment

by:labradorchik
Comment Utility
Thank you! :)  I will try on GURU as well.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now