Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sequential numbering 1

Status
Not open for further replies.

JasonCooper

IS-IT--Management
Dec 14, 2001
20
0
0
GB
HELP !!

I've written a little script that runs every 15 minutes to check a directory on a remote server and ftp any files found to a directory on our Unix server. The script then adds a suffix of .ddmmHHMM to each file.
The user would like this suffix to be a sequential number, preferably padded to 8 digits.

The files may be on our server for sometime so the sequential number would need constantly increase.

ANY help / ideas would be greatly appreciated.

Many thanks
 
Can't you simply write the sequence ID to a file on your server read it, use it, then re-write the file after incrementing it?



William
Software Engineer
ICQ No. 56047340
 
That's very simple and what I was thinking of doing BUT how do you the the increment bit !!??

Cheers
 
In your shell script just use

x=$(($x)) to convert to an int then

let x += 1

or x += 1 depending on your shell.




William
Software Engineer
ICQ No. 56047340
 
Thats great, thanks very much William.
Don't know why I hadn't worked that out myself !!

Cheers
 
In the Korn shell, you can just do this...
[tt]
(( X += 1 ))
[/tt]
A very C like syntax.

Hope this helps.

 
Also, if you want your number zero filled to 8 characters, do the following (also Korn shell)...
[tt]
typeset -Z8 NUM=$(<~/.lastnum.dat)

(( NUM += 1 ))

print ${NUM} > ~/.lastnum.dat

export FILENAME=myfile.${NUM}
[/tt]
This also saves the lastnumber and creates a variable for the file name.

Hope this helps.

 
I'm gonna be a real pain now !!

I'm trying to call the following script from within a standard shell script.
The script fails when run using cron but completes OK running from the command line.

Any ideas ?

£!/bin/ksh
echo 'EXPORT - rename process for file: '$FILE
typeset -Z8 EXP_NUM=$(< /home/ohd/aci/exp_lastnumber)

(( EXP_NUM += 1 ))

print ${EXP_NUM} > /home/ohd/aci/exp_lastnumber

export FILENAME=number.${EXP_NUM}

mv $FILE $FILE'.'$EXP_NUM
 
jason, thanks for letting us know. Something to do with cron's environment (or rather the lack of it!)?
 
SamBones.. thanks for letting us know the typeset -Z8 information... will be very useful for something I got going on...

Thanks again.
 
No problem. Glad to share, that's why I'm here!

[tt]typeset[/tt] is a great one to learn. It can let you do a lot of cool things.

I learned about [tt]typeset[/tt] from The Korn Shell by Anatole Olczak. It's a GREAT book on Korn shell programming and covers a lot of very cool Korn shell features that most people don't seem to know about. Things that give you a lot more power to put into your scripts. You can write some very cool apps using just Korn shell.

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top