File Size Comparison Script

January 27, 2010 at 16:55:13
Specs: Unix/Linux
I am new at scripting and need help developing a script that will look at a diff file size I've created from the original file and compare the size to the orignal and send a return code of 1 to the /etc/notify if the file is less than 6-% of its original size.


If diff_file < 60% of original_file
send return code 1 to start paging.
send return code 0 to stop paging

See More: File Size Comparison Script

Report •

January 28, 2010 at 12:35:59
With some help I have come up with the following script:


file1 = file1.txt
file2 = file2.txt

diff_size=`wc -c $file1 | awk '{ print $1 }'`
orig_size=`wc -c $file2 | awk '{ print $1 }'`

ratio=`echo $diff_size \* 100 / orig_size`
if [ "$ratio" -lt "60" ]; then
echo 1
echo 0

however when I run it I get the following error 3: file1.txt: not found 4: file2.txt: not found

Report •

January 28, 2010 at 15:30:35
file1 = file1.txt
file2 = file2.txt

since they're not quoted, they are intrepreted as variables.
try quoteing them:
file1 = "file1.txt"
file2 = "file2.txt"

i was going to us ls -l, not knowing about wc, so i learned something else today! that's two things i've learned today.
you can dispense with having to use awk if you arrange your word-count like so:
diff1=`wc -c<$file1`

Report •

Related Solutions

Ask Question