compare file size from a output file from a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare file size from a output file from a script
# 1  
Old 11-06-2007
Question 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 SmilieSmilieSmilie

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"
# 2  
Old 11-06-2007
This works for me:

Code:
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.
# 3  
Old 11-07-2007
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?
ThksSmilie
# 4  
Old 11-07-2007
pouf an other issue, I'm fitting with my script to make it reliable SmilieSmilie

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?
# 5  
Old 11-07-2007
comaprison is incorrect

You need to get the file sizes into the variables. For ex,
Code:
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!!!
# 6  
Old 11-07-2007
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
# 7  
Old 11-07-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare size of one file with other file in Linux

Hi, I have 32 files for which I want to check size of each file withe other file and if size is same then some action. Any suggestion to write such script. Logic: have list of 32 files using loop first compare size of one file with remaining 31 , do same iteration for each file with... (4 Replies)
Discussion started by: hemantakhandare
4 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

4. Shell Programming and Scripting

Script to Compare file size and delete the smaller

I am pretty new to scripting, so I appreciate your advice in advance. The problem: 100 directories each containing 2 files that have the same extension with random names. The only attribute that discriminates the files is size. I would like to write a script that compares the files for size... (6 Replies)
Discussion started by: JC_1
6 Replies

5. Shell Programming and Scripting

Output after a perl script gives a file with size zero.

Hi, I have a unix shell script which generates a flat file after connecting to Teradata servers to fetch tables and views and also picks up modified unix scripts from the specified paths. Later on the script calls a perl script to assign a value based on the type of object in the flat file which... (2 Replies)
Discussion started by: yohasini
2 Replies

6. UNIX for Dummies Questions & Answers

PSFTP- Compare file size

Hi, I'm using PSFTP to transfer files from one machine to a virtual machine with UBUNTU OS installed on it. I'm trying to find a way to make sure the files that I'm uploading / downloading are being uploaded/ downloaded properly. I want to compare the size of the local file and the remote... (0 Replies)
Discussion started by: sessie
0 Replies

7. Solaris

Script fails when generated output file reaches a particular size

Hi All, New to unix. Here is the problem. Running a script that extracts data from hyperion essbase and generates a file in unix. This script fails most of the times with a very low success rate. The data has increased a lot in the last few months resulting in the file being more than 2 gb. ... (2 Replies)
Discussion started by: noufalshaw
2 Replies

8. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

9. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

10. Shell Programming and Scripting

How to compare size of two file which is in one directory

I have two file in a Directory.I want a script which will compare the Size of Two file. Can Anyone Help me on this: linasplg11:/opt/dataout/kk/linasplg11 # cat size -rwxrwxrwx 1 root root 16658 Jan 8 13:58 lina_IP_SIP_1231325621210.xml -rwxr-xr-x 1 root root 16672 Jan 8 14:30... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies
Login or Register to Ask a Question