The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare two col from 2 files, and output uniq from file 1 pp56825 Shell Programming and Scripting 2 01-10-2008 11:10 AM
Aggregate values in a file & compare with sql output shiroh_1982 UNIX for Dummies Questions & Answers 1 09-02-2007 07:40 AM
How to compare file size after ftp? icemania Shell Programming and Scripting 1 07-09-2007 11:17 PM
compare 2 files, output dups to file blt123 UNIX for Dummies Questions & Answers 2 07-15-2004 10:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-06-2007
moustik moustik is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 18
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

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 (permalink)  
Old 11-06-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
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 (permalink)  
Old 11-07-2007
moustik moustik is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 18
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
  #4 (permalink)  
Old 11-07-2007
moustik moustik is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 18
pouf an other issue, I'm fitting with my script to make it reliable

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 (permalink)  
Old 11-07-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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 (permalink)  
Old 11-07-2007
moustik moustik is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 18
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 (permalink)  
Old 11-07-2007
moustik moustik is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 18
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0