Subject: | |
From: | |
Reply To: | |
Date: | Mon, 28 Nov 2011 14:31:53 -0800 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Here's a shortcut for leading zeros:
Instead of:
#-- Pad curr with leading zeros --
num="$curr"
for i in 1 2 3 4
do
if [ ${#num} -ge 4 ]; then
break
fi
num="0$num"
done
Use this:
#-- Pad curr with leading zeros --
typeset -Z4 num
num="$curr"
Steve
> -----Original Message-----
> From: HP9000 Computer Systems discussion list
> [mailto:[log in to unmask]] On Behalf Of Keven Miller
> Sent: Monday, November 28, 2011 11:35 AM
> To: [log in to unmask]
> Subject: Re: [HP9000-L] Unique filename - was Aborting an MF
> Cobol/2 program - Answered
>
> ----- Original Message -----
> From: "Tony Summers" <[log in to unmask]>
> To: <[log in to unmask]>
> Sent: Tuesday, November 22, 2011 03:55 AM
> Subject: Re: [HP9000-L] Aborting an MF Cobol/2 program - Answered
>
>
> Next question, which is partly related to this.
>
> Even though we've migrated off the HP3000 (dec 2008), we're still
> running an mpe emulator which has its own job scheduler.
>
> The beauty of MPE/MPUX/AMXW or any other MPE emaulator I have
> forgotten
> to name is that the STDLIST for each job is assigned a unique
> file name
> (on the mpe spooler or its emulated equivalent).
>
> Can someone point me towards tips on how this would be
> emulated in a raw
> unix scripting world ? Or am I about to open a can of worms ?
>
>
> [-----Keven-----]
> Didn't see a response.
> Ok - I'm really an HP3000 programmer, gathering HPUX/Linux experience.
> So thought I'd take a try at this.
>
> This script below (included maybe) shows (one way) how to have an
> incremental
> number that rolls between a base and max values.
> Then using "date" to generate a filename along with our
> incremental number.
>
> Keven Miller
>
> ==========output from run=========================
>
> hpux-1:kevenm /home/kevenm/try#incr
> [base=1 max=16 curr=1]
> NewID: 2
> File 20111128_120223_log0002.txt
> hpux-1:kevenm /home/kevenm/try#ll
> total 32
> -rwxr-xr-x 1 kevenm ranger 1296 Nov 28 12:02 incr
> -rw-rw-r-- 1 kevenm ranger 27 Nov 28 12:02 spool.num
> hpux-1:kevenm /home/kevenm/try#incr
> [base=1 max=16 curr=2]
> NewID: 3
> File 20111128_120226_log0003.txt
> hpux-1:kevenm /home/kevenm/try#incr
> [base=1 max=16 curr=3]
> NewID: 4
> File 20111128_120228_log0004.txt
> hpux-1:kevenm /home/kevenm/try#incr
> [base=1 max=16 curr=4]
> NewID: 5
> File 20111128_120228_log0005.txt
> hpux-1:kevenm /home/kevenm/try#incr
> [base=1 max=16 curr=5]
> NewID: 6
> File 20111128_120229_log0006.txt
> =========================================================
>
> !!!! This is a ksh script !!!!
> ========= incr pasted here - server didn't like my attachment
> ==============
> ###
> # Sample spoolfile number increment with roll calculation
> # file spool.num is created with a base/bottom number, max number,
> # and current number on the first line, seperated by spaces.
> #
> prefix=
> suffix=_log
> ext=.txt
> spoolnum_file=spool.num
>
>
> #----- Unique number -----
> #-- sample file created if doesn't exist --
> if [ ! -r $spoolnum_file ]; then
> echo 1 16 1 >$spoolnum_file
> echo "#base max current" >>$spoolnum_file
> fi
>
> #-- make integer variables --
> typeset -i base
> typeset -i max
> typeset -i curr
>
> read base max curr <$spoolnum_file
> echo "[base=$base max=$max curr=$curr]"
>
> #-- max MUST be >= base --
> if [ $max -lt $base ]; then
> let "max = base";
> fi
>
> let "curr = curr +1";
>
> #-- curr MUST be >= base --
> if [ $curr -lt $base ]; then
> let "curr = base";
> fi
>
> #-- curr MUST be <= max --
> if [ $curr -gt $max ]; then
> let "curr = base";
> fi
>
> echo NewID: $curr
> echo "$base $max $curr" >$spoolnum_file
> echo "#base max current" >>$spoolnum_file
>
>
>
> #----- Unique Date -----
> #-- Make date name variable
> dname=$(date +"%Y%m%d_%H%M%S")
>
>
> #----- Unique filename -----
> #-- Pad curr with leading zeros --
> num="$curr"
> for i in 1 2 3 4
> do
> if [ ${#num} -ge 4 ]; then
> break
> fi
> num="0$num"
> done
>
> #-- New filename --
> fname=${prefix}${dname}${suffix}${num}${ext}
> echo "File $fname"
> ###
>
|
|
|