compare file size from a output file from a script

Hi guys,

firstly I'm working on SunOS 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire-V240

I've made a script to compress two directory and then send them to an other server via ftp. This is working very well.
Inside theis script I decide to log usefull data for troubleshooting in case of need. quit easy until now.
I need to send some information by mail to a anaware person. this information would be the data has been compressed well and are base on the ftp server or the backup transfert hasn't worked well.
Here is starting the interesting clue :confused::confused::confused:

Then I send to a file (INFO) the output of ls -l of the Compressed file and theDIR ftp output
which are like this :

-rwxrwxrwx 1 ftpfintel ftpuser 2103425 Nov 5 11:40 ftptestsys.tar.Z

-rw-r--r-- 1 root root 2103425 Nov 5 11:56 ftptestsys.tar.Z

Then I create a function to sort out and get only file name and size and owner that I send to a file (MAIL).

which is like this :

root 2103425 ftptestsys.tar.Z

ftpfintel 2103425 ftptestsys.tar.Z

Now from this or from an other way, I would like to create a check between the size of the two files. Have you and idea, I'm trying to user

eq but nothing good and do you know how can read the content of MAIL and get something like

MAIL < if [ [0-9] eq [0-9] then echo "transfert ok"
else
echo "transfert defect"

This works for me:

a=100; b=100
if [[ $a -eq $b ]]; then
  echo "File sizes match."
else
  echo "File sizes differ!  Error!"
fi > MAIL

Of course, you would need to plug the file sizes into $a and $b.

Thanks Gus2000

Can you pls let me know how I can plug the file size without creating many files. Is it possible to let the script stay in without doing many files with each output?

If I do my function to get only the size from each it means that the script will create 4 files (1=size ftp, 1=sizefrom system ls for each directory saved)

May be their is a way to keep those info inside the script shell?
Thks:rolleyes:

pouf an other issue, I'm fitting with my script to make it reliable :mad::mad:

here is ...
in the reality for the test a and b are equal number c and d are different number

a=ISL
b=ISF
c=INL
d=INF

eg more $d
48922183

if [ "$c -eq $d" ] ; then echo "Sys File sizes match" ; else echo "Sys File sizes differ Errror" ; fi

When I launch this I get the same reply for both case which is wrong a=b and c diff d

I've tryied may possibilities with [[]] and "" and = but no one is working well. any one can help pls?

You need to get the file sizes into the variables. For ex,

a=`wc -c filename1 | nawk '{print $1}` ## can use a combination of ls and nawk too
b=`wc -c filename2 | nawk '{print $1}'` ## can use a combination of ls and nawk too

##Have used nawk as you have mentioned Solaris. Please change to 'awk' otherwise

Now, the if syntax should work correct. Filenames cannot be used to compare the contents of the files!!!

Thanks ranj@chn

it's very interesting.

It helps me to get less unuseful data file.

But it's not working as well. If I do the test with a=b and c diff d I always get the same answer rather I should get a=b ok c=d not ok

Sure filename cannot be used for that so I create a function here below :

test ()
{
cat $1 |
grep [*.Z] |
awk '{print $5}' |
sed -e 's/printing//g' -e 's/(8192//g' -e 's/on.//g' -e '/^$/d'

test "$INFOSYSL" > "$DIRLOG/ISL"
test "$INFOSYSF" > "$DIRLOG/ISF"
test "$INFONETL" > "$DIRLOG/INL"
test "$INFONETF" > "$DIRLOG/INF"

a=$ISL
b=$ISF
c=$INL
d=$INF

export a b c d

if [ "$a" -eq "$b" ]; then
echo "Sys File sizes match"
else echo "Sys File sizes differ Errror"
fi >> $MAIL

if [ "$c" -eq "$d" ]; then
echo "net File sizes match"
else echo "Net File sizes differ Errror"
fi >> $MAIL

Just to complet. One of the data came from FTP so I have to go accross a file where I push some useful input ls -l and dir result.

What I'm not arriving to do is to read the data and compare it.

Thanks guys to having help me.

With your help I make it works now, so nice to have your support:b::b::b: see below :

check_ftp ()
{
cat $1 |
grep [*.Z] |
awk '{print $5}' |
sed -e 's/printing//g' -e 's/(8192//g' -e 's/on.//g' -e '/^$/d'
}

check_ftp "$INFOSYSL" > "$DIRLOG/ISL"
check_ftp "$INFOSYSF" > "$DIRLOG/ISF"
check_ftp "$INFONETL" > "$DIRLOG/INL"
check_ftp "$INFONETF" > "$DIRLOG/INF"

a=`cat $DIRLOG/ISL`
b=`cat $DIRLOG/ISF`
c=`cat $DIRLOG/INL`
d=`cat $DIRLOG/INF`

export a b c d

if [ "$a" = "$b" ]; then
echo "ok" "\n"
else echo "not ok"
"\n"
fi >> $MAIL

:):):slight_smile: