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

asked on

DCL code to Unit Bash script. How to ZIP files and count ZIP files in Unix Bash script?

Hi everyone,

I am trying to zip in zfiles<state>.zip file multiple (1000s) files (ASCII files) and get a count of each zip file in most efficient way (without dirrectory names and compress better) in Unix Bash script (zipfiles.sh) just like it was in the DCL language below.  If anyone knows how to do the same zipping process in the Unix bash script please let me know. Any suggestions or examples would be appriciated!

Note:  statelist.txt file has all states to loop through


Here is the DCL code portion that I am trying to convert to Unix bash scripting:
define/nolog DATA dir1/data
define/nolog proglog DATA:ZIP.LOG

laststate := ' '

 open/read statelist STATELIST.TXT
read/loop:
 read/end = endread statelist laststate

if f$search("ASCIIFILE%''laststate'%%%%%.TXT").EQS " " THEN -
GOTO READ_LOOP

!-------------------------------------------------------------------------------------------------------------------------------
! Create ZFILES<state>.zip  by zipping all ASCIIFILE files and send ZIP.LOG to the mail list
!-------------------------------------------------------------------------------------------------------------------------------
ZIP  -9V ZFILES'laststate'.ZIP - 
             ASCIIFILE%'laststate'%%%%%.TXT

if .not. $status
 then
  open/append pglog proglog
    write  pglog "--- Error Zipping ASCIIFILE*.TXT files ---"
   close pglog 
       SAY " --- Error Zipping ASCIIFILE*.TXT files ---"
 mail/subject="--- Zipping all files ==> Failure ---" -
  proglog - 
   "@DATA:MAIL.TXT"

else 
 open/append prlog proglog 
 write pglog " * " 
 write prlog "  * DATA:ZFILES''laststate'.ZIP" 
 write prlog " * "
close prlog
SAY " --- Zipping ASCIIFILE*.TXT files ==> Successful ---"

tcounts = tcounts +1
endif

GOTO read_loop

endread:
close statelist

if .not.  $status
  then
SAY " "--- Zipping all files Processing ==> Failure ---"

else
SAY " "
SAY " Zipping all files....  "

open/append prlog proglog
 write prlog " * "
 write prlog " *  Total number of ZIP files created:  ''tcounts' "
 write prlog " * "
close prlog

!------------------------------------------------
!  Sending ZIP.LOG to the mail list
!------------------------------------------------
  SAY " --- Total number of ZIP files created ==> ''tcounts' "
 mail/subject="--- Zipping all files ==> Successful ---" -
  proglog - 
   "@DATA:MAIL.TXT"

delete DATA:statelist.txt

deassign proglog
exit

Open in new window

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

If never heard about DCL before, and this could be the case of many of us.

If you want some help, I suggest you to comment your DCL code, describing plentiful, step by step if necessary, what it does. So we will be able to guess how to translate it into bash code.
Avatar of labradorchik

ASKER

Hi Pierre,

Dialog Control Language (DCL) is a high-level description language and interpreter within AutoCAD for creating simple graphical dialogs. DCL is object-oriented; it allows re-use through inheritance and composition.  

I pretty much would like to zip bunch (1000s) of ASCII files into 50 state zip files by state and then count all of created zip files. DCL code also used to output error/success messages and then sent those messages to a log file as well as sent to a mail list to bunch of emails as notifications of an error or a success.
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

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
Haha! Great.

The last time I touched a VAX computer was in 1991. However, we didn't run VMS (the operating system of DEC for VAX) on that machine, but some UNIX OS, BSD if I remember correctly. So, we never used DCL and this was 28 years ago...

Hoping the answer of the other guys will be more useful for you than mine.
Avatar of noci
noci

I updated the earlier item with a translation. (There are use cases where  OpenVMS is still unsurpassed... and i still am an OpenVMS site maintainer, just curious how the VSI will go with the new incarnation).
The mitigations, separate page tables for kernel / usermode,  that were needed in linux for Spectre & Meltdown were already developped to allow the four modes needed in OpenVMS for process separation [ about 3 -4 years ago, separated page tables for kernel, executive, supervisor & usermode  ].

@Pierre:
And in that timeframe that should indeed have been BSD.
Hi Noci, thank you very much for your explanations and your both examples! Your line-to-line comparisons between the DCL and Bash really makes me understand where and how Bash scripting is different from DCL language.

A few questions:
1. In regards to second example "Shell (bash) only version", on the line 18, how the script knows that "zipfailed=1" ?  
The reason why I am asking this is becasue "zipfailed" previously on the line 6 it was initiated to "0" but how "zipfailed" was changed from "0" to "1"?  Does it change somehow at the time of an error while zipping files?

2. On the line 10, filename="ASCIIFILE?${laststate}?????.TXT"  
Instead of ????? in each file name (ASCIIFILE<var1>.TXT) there would be a variable, correct? For example, "var1" variable that in this case has always a unique value such as ASCIIFILE61616.TXT in one file and in another file ASCIIFILE61617.TXT

I think I did not mention this previoulsy but this "var1" variable with its unique value is also part of each record inside of each correspondedent ASCIIFILE<var1>.TXT file. Just wanted to make sure I am not missing anything.  

Thank you!
1) DCL has the concept of $STATUS as a return status variable and you need to test explicitely.
Unix (or better: Shells like bash, csh, sh bsh, ksh, ...)  has the $? variable.
All Shells also use the syntax:

if command
then
  command
else
  command
fi

The actual wording can be different ( { } in stead of then / fi...)  the command after if is executed  and if it returns 0   == success then the if is true.
if it returns != 0 (1.. 255 ) then it is false.   (In VMS odd $STATUS values is Success.. Generic success SS$_NORMAL has value 1.)

so command:
DCL-CMD
IF $STATUS ...

translates to:
if unix-comand ,,,

likewise:   .not.  translates to !


2) ? is wildcard replacement for % from VMS.
in the original also the state value was explicitly mentions, in a string quoted with "..  variables can be expanded on shells with ${var1}  where VMS uses ''var1' in a string.
Noci, thank you for explanning the differences!!