Unix Script Help Please!

Discussion in 'OT Technology' started by Drifter87, Oct 12, 2007.

  1. Drifter87

    Drifter87 Yippi-kay-ay, Motherfucker

    Joined:
    Jan 5, 2005
    Messages:
    7,173
    Likes Received:
    0
    I take a directory and compare it to a logfile. Then if any files are missing from the logfile, it then prints it out onto the screen.

    Pretty much where I am getting stuck on is how do I take File A line by line and compare it to File B line by line.

    Here is what I got thus far...

    Code:
    #!/bin/bash
    
    [ $# -eq 1 ] || { echo "Invalid Number of Arguments"; exit 1; }
    [  -d $1 ] || { echo "Not A Directory"; exit 1; }
    
    if [ ! -f .logfile ]
    then
            ls $1 > .logfile
    else
            ls $1 > temp1
            for I in `cat .logfile`
            do
                    echo $I
            done
    fi
    
     
  2. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,446
    Likes Received:
    12
    within the for loop you are just echo out each line in the .logfile. I don't see where you are comparing anything, but this is where you are stuck of course.

    You can just use the diff command to see what is missing from your templ compared to the logfile.

    so from this script it seems you run this, checks to see that you have one argument and that the argument is a directory.

    if there hasn't been a .logfile of the current directory, create it.

    if there is, you want to compare.

    you can use a for loop if you have to, and check if `grep $I templ` is successful and then echo out $I.

    instead of the for loop, diff templ .logfile and massage and spit out the output from the diff.

    is this homework or for work?
     
  3. Drifter87

    Drifter87 Yippi-kay-ay, Motherfucker

    Joined:
    Jan 5, 2005
    Messages:
    7,173
    Likes Received:
    0
    This is homework, I'll give what you said a try...
     

Share This Page