Register
It is currently Thu Aug 21, 2014 8:03 am

ssh to servers using bash and expect


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Mar 29, 2011 12:25 am   

Joined: Mon Nov 08, 2010 10:39 am
Posts: 17
Hello,

I need to connect to multiple servers from a local machine with a root password. I need to connect to a server over ssh, perform a command, exit and connect to the next server. Usual thing, I would say. Of course, there are some good examples in the internet. The most suitable is the one listed below:

Code:
##!/bin/bash
set -x
host="hostname"
user=root
passw='password'
cmd='ls -la'
socket=$(expect -c "
spawn ssh -o StrictHostKeyChecking=no $user@$host $cmd
match_max 100000
expect \"*password:*\"
send -- \"$passw\r\"
send -- \"\r\"
expect eof
")
echo "$socket"


This script connects fine at home to my server set up in VirtualBox. But I cannot connect at work. I am attaching a file with all output I see. I would be grateful for any help. Of course I am replacing password and hostname. I assure you I set the correctly them with no typos.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 PostPosted: Tue Mar 29, 2011 1:45 am   

Joined: Mon Nov 08, 2010 10:39 am
Posts: 17
Ok, this is because of 'StrictHostKeyChecking no' set in the /etc/ssh/ssh_config file.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Watael and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP