1

I want a script that ssh to remote server and then run a script which is at my local machine and then store the output on my local machine

Expect script for ssh to remote server:

#!/usr/bin/expect -f set Timeout 2 set IPaddress 10.118.137.78 set Username "username" set Password "password" spawn ssh $Username@$IPaddress expect "ssword:" send "$Password\r" 

script to be run on remote machine and gather the data:

#!/bin/sh for serveraddress in `cat list.out` do "seeisso $serveraddress | grep -E -i ' os |proddropdown'" done >> getos 

=== Not sure how to : 1. combine both and get the result. 2 in expect script it does not takes the \r and returns to newline.

1 Answer 1

1

Quick sample

#!/usr/bin/expect -f set timeout -1 set Username "user" set password "pass" set ipaddress "host" set script "script-name" spawn $env(SHELL) send -- "ssh $Username@$ipaddress $script\r" expect "assword: " send -- "$password\r" send -- "exit\r" expect eof 

That will work to execute the script on the remote side. I didn't toy with it too much but when it's done you have to Ctrl+C to exit expect. At this point I'd be setting up ssh keys for a small environment and for a larger use puppet or something to manage it then for even larger go for single sign-on probably kerberos.

3
  • I have to put script on remote machine? Commented Apr 24, 2013 at 16:24
  • is there a away i can execute the script which is on my local machine ? Commented Apr 24, 2013 at 16:25
  • what are the -- dashes after "send" for? Commented May 29, 2015 at 5:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.