LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2009, 07:08 AM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
List missing files - help writing a script


Hello!

In my log directory there are a lot of files:

log000001.txt
log000002.txt
...
log000123.txt
log000124.txt
log000130.txt
log000131.txt
...
log000600.txt

Notice that files between log000124.txt and log000130.txt are missing (5 files).

Now, I want to write a script that shows me the missing files (or just numbers...). It is very hard to check manually.

Thank you

Last edited by laki47; 03-30-2009 at 07:09 AM.
 
Old 03-30-2009, 08:10 AM   #2
eco
Member
 
Registered: May 2006
Location: BE
Distribution: Debian/Gentoo
Posts: 412

Rep: Reputation: 48
Try somethin in the lines of:

reviewed (messy but works).
Code:
#!/bin/bash

total=`ls -t log0000*.txt|tail -n1|cut -d. -f1|cut -dg -f2`

for i in `seq -w 1 ${total}`; do
   [ ! -f log*${i}.txt ] && echo "Missing: ${i}"
done
done

I have no access to a shell right now so this is theoretical. I'll test it with a shell in a few minutes if it doesn't work.

Last edited by eco; 03-30-2009 at 08:16 AM.
 
Old 03-30-2009, 08:35 AM   #3
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
Are the upper and lower boundries always the same? (001 and 600)?
 
Old 03-30-2009, 08:55 AM   #4
laki47
Member
 
Registered: Feb 2009
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by john test View Post
Are the upper and lower boundries always the same? (001 and 600)?
I'm afraid not...
 
Old 03-30-2009, 08:59 AM   #5
eco
Member
 
Registered: May 2006
Location: BE
Distribution: Debian/Gentoo
Posts: 412

Rep: Reputation: 48
Have you had a chance to try my script? It's basic but it should do the job as a quick fix.
 
Old 03-30-2009, 09:04 AM   #6
laki47
Member
 
Registered: Feb 2009
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by eco View Post
Have you had a chance to try my script? It's basic but it should do the job as a quick fix.
I will be able to try it later...

Thank you

...

It is working great!

Thanks!

Last edited by laki47; 03-30-2009 at 12:37 PM.
 
Old 03-30-2009, 12:11 PM   #7
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
What process triggers the writing of the log file?
Pmce you know what that process is then you can determine what causes it to either write or not write the Lov file.
Then you can make that process increment a counter no matter what the descision was and that will give you the end point.
you need an endpoint so you can deal with the case where the process failed to write a log file for the last N instances after the last log file was written. e.g. 601, 602 etc.
 
Old 03-30-2009, 12:58 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this mite work
[untested]
Code:
for i in `seq 1 999999`
do
 zero-pad-2.x $i
done > list.num

ls -1 log*.txt | cut -b 4-9 > log.lst

grep -v -f list.num log.lst
# diff list.num log.lst
source to zero-pad-2.c:
Code:
#include "stdio.h"
#include "string.h"
 
 
char *strrev(char *s){
    char *p=s;
    char *q =s;
    char swap;
    if (*s)
    {
        q=strchr(q,'\0');
        while (--q > p)
        {
            swap = *q;
            *q = *p;
            *p = swap;
            ++p;
        }
    }
    return s;
}
 
 
main(int argc, char *argv[])
{
        char col1[255], col2[255];
        int c;
 
         while(strlen(argv[1]) < 2)
         {
          strcpy(argv[1], strrev(argv[1]));
          strcat(argv[1], "0");
          strcpy(argv[1], strrev(argv[1]));
         }
         printf("%s\n", argv[1]);
}

Last edited by schneidz; 03-30-2009 at 01:06 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apt-get dpkg error: files list file ... missing final newline PBSchmidt Debian 13 04-29-2023 05:55 PM
Need help in writing a script to move old files... NYMets91587 Linux - Newbie 9 02-20-2009 05:43 AM
Script to list files in a given directory Azzath Programming 8 04-03-2008 07:02 AM
writing awk script files bigmark Linux - Software 1 10-19-2005 10:33 AM
Missing List.* files in URPMI directory Ronw Linux - General 2 10-08-2003 03:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration