The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Merge Log Files

Discussion in 'General Discussion' started by lloyd_tennison, Sep 6, 2005.

  1. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    I had my server OS updated and the log files did not get copied before the server was restarted. Has any of or gurus out here ever written a script to merge two files? (Or can write a script?) I figure that a base could be from a script - as that reads all the users, etc.
     
    #1 lloyd_tennison, Sep 6, 2005
    Last edited: Sep 6, 2005
  2. DigiCrime

    DigiCrime Well-Known Member

    Joined:
    Nov 27, 2002
    Messages:
    399
    Likes Received:
    0
    Trophy Points:
    16
    Think you can pass it thru cat like cat file | something something I forgot the rest now, if someone else knows they can fill in the blanks :cool:
     
  3. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    It's easy enough to append a file in unix:

    cat from.file >> dest.file
     
  4. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    No, I meant to scan through all the users, then move the old files and cat the new file to the bottom. I know it an be done one by one - but do not want to have to do all those domlogs (three each user) if I do not have to.

    I just do not know how to script it to scan and move.


    Boy I wish they had not forgotten that on the upgrade!
     
  5. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    I have written this mod - but was hoping someone could show me (I am a hacker not a programmer) how to recurse /etc/localdomains and do this or even to read the files from the directory. That way I could make it do the /var/logs directory also.

    Code:
    #!/usr/bin/perl
    system("service httpd stop;");
    system("cp /usr/local/apache/domlogs/$ARGV[0] /usr/local/apache/domlogs/old.$ARGV[0]; cp /usr/local/apache/domlogs/ftp.$ARGV[0] /usr/local/apache/domlogs/old.ftp.$ARGV[0]; cp /usr/local/apache/domlogs/$ARGV[0]-bytes_log /usr/local/apache/domlogs/old.$ARGV[0]-bytes_log; cp /usr/local/apache/domlogs/$ARGV[0]-bytes_log.offset /usr/local/apache/domlogs/old.$ARGV[0]-bytes_log.offset; cp /usr/local/apache/domlogs/$ARGV[0]-smtpbytes_log /usr/local/apache/domlogs/old.$ARGV[0]-smtpbytes_log;");
    system("cp /old/usr/local/apache/domlogs/$ARGV[0] /usr/local/apache/domlogs/$ARGV[0]; cp /old/usr/local/apache/domlogs/ftp.$ARGV[0] /usr/local/apache/domlogs/ftp.$ARGV[0]; cp /old/usr/local/apache/domlogs/$ARGV[0]-bytes_log /usr/local/apache/domlogs/$ARGV[0]-bytes_log; cp /old/usr/local/apache/domlogs/$ARGV[0]-bytes_log.offset /usr/local/apache/domlogs/$ARGV[0]-bytes_log.offset; cp /old/usr/local/apache/domlogs/$ARGV[0]-smtpbytes_log /usr/local/apache/domlogs/$ARGV[0]-smtpbytes_log;");
    system("cat /usr/local/apache/domlogs/old.$ARGV[0] >> /usr/local/apache/domlogs/$ARGV[0]; cat /usr/local/apache/domlogs/old.ftp.$ARGV[0] >> /usr/local/apache/domlogs/ftp.$ARGV[0]; cat /usr/local/apache/domlogs/old.$ARGV[0]-bytes_log >> /usr/local/apache/domlogs/$ARGV[0]-bytes_log; cat /usr/local/apache/domlogs/old.$ARGV[0]-bytes_log.offset >> /usr/local/apache/domlogs/$ARGV[0]-bytes_log.offset; cat /usr/local/apache/domlogs/old.$ARGV[0]-smtpbytes_log >> /usr/local/apache/domlogs/$ARGV[0]-smtpbytes_log ;");
    system("service httpd start;");
    system("rm -f /usr/local/apache/domlogs/old*;");
    
    
    If anyone has any ideas - I would appreciate it. I keep losing the domain name on anything I try. (I do replace th ARGV value on my trials.)
     
    #5 lloyd_tennison, Sep 9, 2005
    Last edited: Sep 9, 2005
  6. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Code:
    #!/usr/bin/perl
    
    open (datafile,"/etc/localdomains");
    @doms = <datafile>;
    close (datafile);
    
    system("service httpd stop;");
    
    foreach $_ (@doms) {
    chomp($_);
    system("cp /usr/local/apache/domlogs/$_ /usr/local/apache/domlogs/old.$_; cp /usr/local/apache/domlogs/ftp.$_ /usr/local/apache/domlogs/old.ftp.$_; cp /usr/local/apache/domlogs/$_-bytes_log /usr/local/apache/domlogs/old.$_-bytes_log; cp /usr/local/apache/domlogs/$_-bytes_log.offset /usr/local/apache/domlogs/old.$_-bytes_log.offset; cp /usr/local/apache/domlogs/$_-smtpbytes_log /usr/local/apache/domlogs/old.$_-smtpbytes_log;");
    system("cp /old/usr/local/apache/domlogs/$_ /usr/local/apache/domlogs/$_; cp /old/usr/local/apache/domlogs/ftp.$_ /usr/local/apache/domlogs/ftp.$_; cp /old/usr/local/apache/domlogs/$_-bytes_log /usr/local/apache/domlogs/$_-bytes_log; cp /old/usr/local/apache/domlogs/$_-bytes_log.offset /usr/local/apache/domlogs/$_-bytes_log.offset; cp /old/usr/local/apache/domlogs/$_-smtpbytes_log /usr/local/apache/domlogs/$_-smtpbytes_log;");
    system("cat /usr/local/apache/domlogs/old.$_ >> /usr/local/apache/domlogs/$_; cat /usr/local/apache/domlogs/old.ftp.$_ >> /usr/local/apache/domlogs/ftp.$_; cat /usr/local/apache/domlogs/old.$_-bytes_log >> /usr/local/apache/domlogs/$_-bytes_log; cat /usr/local/apache/domlogs/old.$_-bytes_log.offset >> /usr/local/apache/domlogs/$_-bytes_log.offset; cat /usr/local/apache/domlogs/old.$_-smtpbytes_log >> /usr/local/apache/domlogs/$_-smtpbytes_log ;");
    }
    
    system("service httpd start;");
    system("rm -f /usr/local/apache/domlogs/old*;");
    
    
     
Loading...

Share This Page