Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 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.

share|improve this answer
    
I have to put script on remote machine? –  nis Apr 24 '13 at 16:24
    
is there a away i can execute the script which is on my local machine ? –  nis Apr 24 '13 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.