Operating System - HP-UX
1832839 Members
2890 Online
110047 Solutions
New Discussion

Re: script to sequence log files

 
SOLVED
Go to solution
Vin_4
Occasional Contributor

script to sequence log files

Hi all,

I have a script for sequencing log files from 00 to 59 using:

27 typeset -Z2 N

30 for F in $FILE_LIST
31 do
32 (( N=(N+1)%60 ))
33 mv ${F} $DEST/${N}${F}
34 done

When I run it however I get the following:

./sequence.sh[32]: 08: The specified number is not valid for this command.

Any ideas?

Many thanks.
12 REPLIES 12
Pete Randall
Outstanding Contributor

Re: script to sequence log files

Vin,

You might want to look into the Logrotate tool:

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/logrotate-2.5/


Pete

Pete
Mark Grant
Honored Contributor

Re: script to sequence log files

This might be the bug that got the posix shell recognizing numbers beginning with 0 as octal.

Try this patch or the latest version of it.

PHCO_29816
Never preceed any demonstration with anything more predictive than "watch this"
Juergen Tappe
Valued Contributor

Re: script to sequence log files

Try to change the line :

(( N=(N+1)%60 ))

into :

N=$(( (N+1) % 60 ))

should work...
Working together
Vin_4
Occasional Contributor

Re: script to sequence log files

Hi all,

thanks for replies so far.

Mark, I think you may be right with that, one system was patched 3 weeks ago (script does not work on this system now), works fine on the un-patched systems.

Maybe changing "typeset" could do the job? any ideas?

Thanks.
Mark Grant
Honored Contributor

Re: script to sequence log files

well, I guess changing the "typeset" or just not using it at all would prove if it's the "leading zeros are octal" problem.

If you are having problems though, the solution, as is so often the case, is to simplify. You could go

(( N=N+1 ))
[[ $N -gt 60 ]] && N=0
Never preceed any demonstration with anything more predictive than "watch this"
Bharat Katkar
Honored Contributor

Re: script to sequence log files

Hi There,

This worked for me:

For "(( N=(N+1)%60 ))" i did

let N=$N+1
let N=$N/60

Regards,




You need to know a lot to actually know how little you know
Vin_4
Occasional Contributor

Re: script to sequence log files

Hi Mark,

That's nearly what I need, I have to keep the sequence numbers to 2 digits though.

Is there another way to do this?
Mark Grant
Honored Contributor

Re: script to sequence log files

Vin,

If you want to keep it really simple (and nasty) then add this ugly bit in too

(( N=N+1 ))
[[ $N -gt 60 ]] && N=0
[[ $N -le 10 ]] && N="0$N"

Horrible isn't it but if you're having problems why not make it ugly but working in my view :)
Never preceed any demonstration with anything more predictive than "watch this"
Vin_4
Occasional Contributor

Re: script to sequence log files

Back to the same problem with the 'ugly' fix unfortunately

27 #typeset -Z2 N

30 for F in $FILE_LIST
31 do
32 (( N=N+1 ))
33 [[ $N -gt 60 ]] && N=0
34 [[ $N -le 10 ]] && N="0$N"


./sequence.sh[32]: 09: The specified number is not valid for this command.
John Poff
Honored Contributor
Solution

Re: script to sequence log files

Hi,

I think I have your code working. I think the trick is around the typeset command and the octal problem mentioned. I got it to work by using another variable to calculate the number, and then setting the variable N to that number.

Something like this:

typeset -Z2 N
T=0

for F in $FILE_LIST
do
(( T=(T+1)%60 ))
N=$T
mv ${F} $DEST/${N}${F}
done


It looks like your arithmetic expression works, but not with a variable where you have the typeset for -Z2.

JP



Bharat Katkar
Honored Contributor

Re: script to sequence log files

typeset -Z2 N=
for F in $FILE_LIST
do
(( N=N+1 ))
[[ $N -gt 60 ]] && N=0
[[ $N -le 10 ]] && N="0$N"


Hope that should work.
Regards,
You need to know a lot to actually know how little you know
Vin_4
Occasional Contributor

Re: script to sequence log files

That works John, thanks!