Is it possible to compare the sizes of two files from within a Bash script? I don't need to know the actual sizes just which one is the bigger file. I can't find anything useful in the Bash man page. Barry Samuels
on Tue, Jul 17, 2001 at 09:14:17PM +0100, bsamuels@datamansys.co.uk scribbled:
Is it possible to compare the sizes of two files from within a Bash script? I don't need to know the actual sizes just which one is the bigger file.
not optimal, but it works and is relatively clear.. file1=/etc/profile file2=/etc/passwd if [ ! -f "$file1" ] then echo "$file1 does not exist" exit else if [ ! -f "$file2" ] then echo "$file1 does not exist" exit fi fi file1size=`wc -c "$file1" | awk '{print $1;}'` file2size=`wc -c "$file2" | awk '{print $1;}'` if [ "$file1size" -gt "$file2size" ] then echo "$file1 is bigger" else if [ "$file1size" -lt "$file2size" ] then echo "$file1 is smaller" else echo equal sizes fi fi
Three people kindly replied to my previous post with three different suggestions all of which work. Many thanks for those. I am afraid that I shall have to drag this out a little longer as one of the files involved in the comparison is on a remote server and I haven't been able to find a way of logging on automatically. I can use only Telnet or Fpt to gain access to the appropriate directory and I cannot find a way of sending my password via telnet which always supplies a 'Password:' prompt. Telnet allows me to provide my user name when I start it or via 'Open' but there appears to be no option for Passsword. Can I automate this process from within a script? Barry Samuels
on Wed, Jul 18, 2001 at 05:39:11PM +0100, bsamuels@datamansys.co.uk scribbled:
I can use only Telnet or Fpt to gain access to the appropriate directory and I cannot find a way of sending my password via telnet which always supplies a 'Password:' prompt. Telnet allows me to provide my user name when I start it or via 'Open' but there appears to be no option for Passsword.
Can I automate this process from within a script?
you could use wget(1) and access the file via ftp? wget ftp://username:password@host/dir/file or if you can, install scp/ssh and use dh/dsa key pairs
--- bsamuels@datamansys.co.uk wrote:
Three people kindly replied to my previous post with three different suggestions all of which work. Many thanks for those.
I am afraid that I shall have to drag this out a little longer as one of the files involved in the comparison is on a remote server and I haven't been able to find a way of logging on automatically.
I can use only Telnet or Fpt to gain access to the appropriate directory and I cannot find a way of sending my password via telnet which always supplies a 'Password:' prompt. Telnet allows me to provide my user name when I start it or via 'Open' but there appears to be no option for Passsword.
Can I automate this process from within a script?
"Expect" is what you want. We have used it to send uuencoded text over telnet instead of FTP. Thanks D
Barry Samuels
_______________________________________________ alug, the Anglian Linux User Group list Send list replies to alug@stu.uea.ac.uk http://www.anglian.lug.org.uk/ http://rabbit.stu.uea.ac.uk/cgi-bin/listinfo/alug See the website for instructions on digest or unsub!
===== -------------------- "We all know Linux is great... it does infinite loops in 5 seconds." Linus Torvalds __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
David Freeman wrote:
--- bsamuels@datamansys.co.uk wrote:
"Expect" is what you want. We have used it to send uuencoded text over telnet instead of FTP.
This is probably a bit old by now, but here's my script for connecting to cpca4 thru zen: #!/usr/bin/expect -f spawn telnet zen.sys.uea.ac.uk set timeout -1 expect { ogin: { send "u9953647\r"; } } expect { sword: { send "z78376r\r"; } } expect { > { send "telnet -a cpca4\r"; } } expect { sword: { send "z78376r\r"; } } interact And for the folks with raised eyebrows, yes I did change the password. -1 disables timeout on 'expect' Alexis
participants (4)
-
Alexis Lee -
bsamuels@datamansys.co.uk -
David Freeman -
xsprite@bigfoot.com