LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-29-2003, 10:24 AM   #1
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Rep: Reputation: 30
problems with ssh in scripts using expect


so i'm wanting to be able to compare file sizes on two different machines. best way i know how to is to write a script to capture filesize on one and then ssh into another machine and get the filesize on that machine. however i'm having problems getting ssh to work.

ssh -l myname name.computer.com

doesn't seem to be working. neither does substituing ip for name.computer.com. anyway, if anyone knows exaclty how to use ssh in a script/ commandline i should be able to use expect to get it work....unless you know of a better way to get the file sizes off the other machine remotely.

Last edited by wedgeworth; 09-30-2003 at 03:43 PM.
 
Old 09-29-2003, 10:34 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
It is probable getting hung looking for a password. To run it without passwords and using DSA keys:
1) login as USER on the client (where you want to connect from)
2) ssh-keygen -t dsa
(don't suppy a passphrase now - you can do that later once the first bit works)
3) scp /home/USER/.ssh/id_dsa.pub REMOTEHOST:/home/USER/.ssh/authorized_keys2
(you will need to enter your password this one time)

The next time you ssh it shouldn't need a password to conenct from that box.
 
Old 09-29-2003, 12:11 PM   #3
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
.

Last edited by wedgeworth; 09-29-2003 at 12:13 PM.
 
Old 09-29-2003, 12:12 PM   #4
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
at the moment i've got ssh working, so i can reference files on both systems. right now i'm having a problem getting the filesizes referenced so i can assign them to some varialbe. so far i'm pulling off string of information instead of just the number/filesize itself. anyway could anyone be of assistance for a very simple question: get just the filesize in a variable so i can do some comparisons. thanks
 
Old 09-29-2003, 03:54 PM   #5
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
having problem with syntax of expect. below i'm trying to print out the file sizes of two identical files located on different servers. i think the ssh seems to be working alright but some of the usual bash syntax doesn't work with expect. any help would be appreciated.



/************************************

#!/usr/bin/expect -f
#!/bin/sh

set HOSTNAME steve
set BPATH /usr/var/backups

set DATE [exec date +%m-%d-%y]
set SIZE1 [exec find backup.$HOSTNAME.$DATE.tar -printf %s]

set timeout -1

cd $BPATH/
spawn ssh -l backup backup@www.bob.com
expect -re "backup@www.bob.com's password:"
send "****\r"
#expect
#wait
#interact

cd /Volumes/extdrive1/serverBackups
set SIZE2 [exec find backup.$HOSTNAME.$DATE.tar -printf %s]

#leave bob remote acess
exit

exec echo "$SIZE1 $SIZE2"
 
Old 09-29-2003, 09:21 PM   #6
m0rl0ck
Member
 
Registered: Nov 2002
Distribution: A totally 133t distro :)
Posts: 358

Rep: Reputation: 31
After you do the key exchange as explained above, this command will return a file size on the remote machine:
ssh REMOTEHOST du -sh /complete/path/to/remotehost/file|cut -f1|tr A-Z " "

This will return only a number. If you want the letter description included use:
ssh REMOTEHOST du -sh /complete/path/to/remotehost/file|cut -f1

this will return the number and a K for kilobytes or an M for megabytes
 
Old 09-30-2003, 10:59 AM   #7
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
thanks for the help but now i'm trying to get the syntax right for catching the return. and assigning it to a varible as well as echoing the variable later. have been having problems with some of that before. can't quite get the syntax down correct.

exec echo "$DATE"

doesn't seem to be working. no errors, it's just not doing anything.
 
Old 09-30-2003, 01:18 PM   #8
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
.

Last edited by wedgeworth; 10-01-2003 at 05:08 PM.
 
Old 10-01-2003, 09:02 AM   #9
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
.

Last edited by wedgeworth; 10-01-2003 at 05:09 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
having problems with shell scripts please help !!!!!! max_rsr Programming 1 04-21-2005 06:01 AM
Problems with perl and irssi-scripts.. magoot Programming 0 02-27-2005 06:24 AM
Problems running irssi scripts eviltama Linux - Software 0 05-13-2004 01:30 AM
ssh using shell scripts Alek Linux - Networking 4 09-05-2003 02:28 PM
SSH using shell scripts Alek Linux - General 2 08-28-2003 03:52 PM


All times are GMT -5. The time now is 04:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration