Link to home
Start Free TrialLog in
Avatar of labradorchik
labradorchikFlag for United States of America

asked on

VAX DCL code to UNIX bash shell script conversion

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

Avatar of Pierre François
Pierre François
Flag of Belgium image

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.
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.
Avatar of labradorchik

ASKER

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.
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.
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?
ASKER CERTIFIED SOLUTION
Avatar of David
David
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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.
Thank you for your comments!!
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.
Thank you! :)  I will try on GURU as well.