help - script can check jump sequence?

Hi,

if I have a lot of files like (AABBCC0010, AABBCC0011, AABBCC0012....AABBCC1000), can I write a small script to check any sequence number jump and show me the result which sequence number?

#The first sequence may start from 0010 or 0101... :confused:

Thank you!!

You can write a small script to do that. Here is one that I wrote:

#!/bin/sh
start=1

for file_number in  `ls -1 AABBCC* | sort | cut -c 7,8,9,10`
do
    if [ $start = 1 ] ; then
    # this is the first pass of the loop, so we've got nothing to compare
        start=0
    else
    # this is not the first pass of the loop
        previous=`expr $previous + 1`
        echo "comparing $file_number and $previous ... "
        if [ $file_number = $previous ] ; then
            echo "file names are in sequence "
        else
            echo "file names $file_number are not in sequence "
        fi
    fi
    previous=$file_number
done

I assumed that filenames are AABBCCxxxx where xxxx is a number, which is of interest to us. Please note that this script does not work with smaller numbers, of 3 digits and 2 digits. Reason is that expr strips the leading zeros in such numbers (0010 becomes 10 which then breaks the sequence)

not work..
when I run the script, it showing the error below:

expr: non-numeric argument
comparing SIMAC and  ... 
ksh: test: argument expected
file names SIMAC are not in sequence 
expr: non-numeric argument
comparing SIMAC and  ... 
ksh: test: argument expected
file names SIMAC are not in sequence 
expr: non-numeric argument

if [ $start = 1 ] replace with if [ $start -eq 1 ]
and if [ $file_number = $previous ] with if [ $file_number -eq $previous ]

You are using ksh to execute this script. Try using sh. Run it as:

$ sh scriptname

where scriptname is the name of the script

I try to run:

sh checkseq (scriptname)

it showing:

expr: non-numeric argument
comparing SIMAC and  ... 
checkseq: test: argument expected

The variable previous is not initialised.
Modify the script :

if [ $start -eq 1 ] ; then
   # this is the first pass of the loop, so we've got nothing to compare
   start=0
   previous=$file_number
else

Jean-Pierre.

an alternative in Python:

#!/usr/bin/python
import os
os.chdir("/dir_with_lots_of_files")
files = [ f for f in os.listdir(os.getcwd()) ] #eg ['AABBCC0010', 'AABBCC0011', 'AABBCC0012', 'AABBCC0013', 'AABBCC0014', 'AABBCC0015', 'AABBCC0018', 'AABBCC0020', 'AABBCC0021']
num = map(str, sorted( [ int(i[-4:]) for i in files ] ) )
for iter in range( int(num[0]) , int(num[-1]) + 1):
     if not str(iter) in num: 
           print "Sequence stop at ", str(iter)

an alternative in Python:

#!/usr/bin/python
import os
os.chdir("/dir_with_lots_of_files")
files = [ f for f in os.listdir(os.getcwd()) ] #eg ['AABBCC0010', 'AABBCC0011', 'AABBCC0012', 'AABBCC0013', 'AABBCC0014', 'AABBCC0015', 'AABBCC0018', 'AABBCC0020', 'AABBCC0021']
num = map(str, sorted( [ int(i[-4:]) for i in files ] ) ) #eg ['10', '11', '12', '13', '14', '15', '18', '20', '21']
for iter in range( int(num[0]) , int(num[-1]) + 1):
     if not str(iter) in num: 
           print "Sequence stop at ", str(iter)

Output:

Sequence stop at 16
Sequence stop at 17
Sequence stop at 19

Hi aigles, your modified look work.... :o

Thanks all!

Hello,

I need Unix script for Checking sequence and get output in a file for missing sequences information.
We are moving archive log to a server for DR .if any files miss from sequence DR will fails. so we need script to monitor sequence of files which are FTP from the Production servers .
Some plz provide me script for the same .

Thanks in Advance

Raj