0

I wrote the bellow script the purpose of the script is to find all files that start with foo and are no older 3 days sort them then compare them against the list of files in the list file. And to repot only files that are missing. The problem with my script is that it doesn’t not take in to account a missing file ie see below example Let’s say my file called list contains foo1, foo2, foo3, foo4, foo5 but in the event that one file files is missing the string comparison is off. Ie if file foo4 is missing when the script is ran foo5 would be compared foo4

Hope that makes sense

enter  

#!/bin/bash
Set –x
Find ~/test99 –name “foo*” –mtime -3 –print>report
Sort report –o report;
Cat report|cut -c 22-25>report1;
while read comp1<&3 && read comp2<&4
do
    if [[ $comp1 = $comp2 ]]; then
    echo "file not found" >/dev/null
else
    echo "$comp1 not found"
fi
done 3<report1 4<list
1
  • 1
    You forgot the dollar sign before the comp2 variable in the comparison. It should be if [[ $comp1 == "$comp2" ]]; then Commented Aug 16, 2013 at 16:02

1 Answer 1

1

you might want to use diff for comparing the lists

or you can use fgrep -vf report list to get the difference between list and report

Sign up to request clarification or add additional context in comments.

5 Comments

How do you suggest I use diff as I am testing to see if a list of files exists by having it take input from the file called “list” then using find to search for a list of files and output the results to file called reports and compare the output to the list file.
it would greatly aid giving a better answer if you could clarify the question more clearly....i think you want to get the difference between list and report
Ok I understand what you are saying now. I am using fgrep –vf to get the difference which is working. But I only want it to echo what file is missing. My code now looks like the below. The test is working as it should be but my logic is wrong. I would it to only echo when a file is missing Fgrep –vf report1 output If [[ -s $output ]] then Echo no file missing else Echo “a file is missing” fi
The file “output” file always tests true regardless if it exists and contains a size grater then 0.
Never mind I figured it out. Thanks for pointing me in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.