Results 1 to 4 of 4
  1. #1
    Join Date
    May 2008
    Posts
    3

    Cool Unanswered: partially executing shell script

    hi guys. I have written the following shell script..
    What the script does is it traverses a directory & compares files in that directory..
    it traverses a file and if that has a include line it cuts out the name present in the include <> and tries to find a file of that name in the same directory..if the names are garbled then it rectifies it...

    however when i execute it, it does work good for initial files and then hangs up..as in it doesn;t traverse the whole directory..which is wierd

    here is the script.

    #!/bin/sh
    # Script for checking the CaSe of filenames in include statements

    #rootdir is where all the child files reside
    rootdir=/vobs/wsCore/mibs

    child_file_count=0

    # The for loop for going through the entire directory but checking only those files with mib in their names

    for file in `ls $rootdir | grep -i "mib"`
    do

    # parse all include statements in the next child file by a case-insensitive search
    # cut relevant fields remove the quotes redirect the output to a temporary file called test

    grep -i "<include>:" $rootdir\/$file | cut -d' ' -f4- | sed 's/\"//g' > test

    #Also store this in a variable for future filename comparison with parent files
    var_child_i=`grep -i "<include>:" $rootdir\/$file | cut -d' ' -f4- | sed 's/\"//g'`

    #now we deal with the temporary file i.e. test file

    for i in `cat test`
    do
    ls $rootdir > list
    # A case-sensitive search on list of files in root directory to check if filenames match
    # capture parent filename
    var_par_s=`grep "$i" list`
    echo $var_par_s

    #perform a case-insensitive search on the list of files in root directory to capture
    #anyhow the parent filename for future comparisons
    var_par_i=`grep -i "$i" list`
    echo $var_par_i

    #check if var_par_s is empty, if empty, no file with that name exists in mib folder
    # i.e. case is wrong in original file

    if [ -n "$var_par_s" ]
    then
    echo Parent file found.. Modification of child file $file NOT needed
    else
    echo Parent file NOT found.
    echo Hence we need to modify the child file \= $file containing the erroroneous name \"$var_child_i\"

    #check OUT the child file
    cleartool checkout -unreserved -comment "For checking include statement" $rootdir\/$file
    echo File $file Checked OUT of VOB

    #Modify the include statement in the child file to reflect the parents name
    echo Now every instance of \"$var_child_i\" will be replaced by \"$var_par_i\"
    sed "s/$var_child_i/$var_par_i/g" $rootdir\/$file > aliasfile
    mv aliasfile $rootdir\/$file
    echo File $file\'s modification successful

    #Check IN the child file
    #cleartool checkin $rootdir\/$file
    echo File $file checked back IN the VOB
    fi

    child_file_count=`expr $child_file_count + 1`

    done

    done

    echo The total number of child files traversed \= $child_file_count
    echo Program execution ends\!

  2. #2
    Join Date
    May 2008
    Posts
    3
    Also...is there someway i can check if the traversing with the for loop reaches the end of the directory ?? or does the for loop take care of that itself??

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    I'd just keep a list of files that have already been processed and another list of files to be processed.

    Proc A) You could have a little routine that will add a file to the "to do" list only if not in the "done" list. This would be easy to test separately.

    Proc B) Next you'd want something that takes a file and extracts all the new files from it. Again easy to test.

    Next you'd set up a loop that pulls a file from the "to do" list. You don't want to do foreach file in `cat to_do_list` because you'll be adding new files to the list as you go along.

    Call proc B) to get all the files accessed by that file and then use proc A) to add them to the "to do" list if not already in there.

    Once a file has been loaded then it goes into the "done" list.
    Unsure if that made sense but at least it's easier to read than unformatted shell script written by someone else

    Mike

  4. #4
    Join Date
    May 2008
    Posts
    3


    Thanks man..
    your idea looks great...I think that will work..
    In case i run into problems, i ll get back..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •