Expect Script - error using sed -

Guys,

I'm testing a simple script that connects to a server, does a few checks and sends the results to a file.

code:

#!/bin/ksh

expect <<-EOF | sed 's/^M//' >> file
spawn ssh user@server
expect "password:" { send "password \n" }
expect "$"
send "df -k /dev/md/dsk/d10 | tail -1 \n"
expect "$"
send "exit \n"
EOF

I do get a sed error:
sed: Missing newline at end of file standard input.

Also, is there a better way to do this? I'm planning to run several health checks on a few servers.

Thank you
Tony

yes. if you check the help or man page of ssh

ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
[-D port] [-e escape_char] [-F configfile] [-i identity_file] [-L
port:host:hostport] [-l login_name] [-m mac_spec] [-o option]
[-p port] [-R port:host:hostport] [-S ctl] [user@]hostname [command]
There's a [command] you can use

I dont have a problem with ssh.

I have a problem removing all the return characters using sed.

Tony

for your case above, the ssh can execute "command" , ie "df -k /dev/md/dsk/d10 | tail -1" remotely..

syntax:

ssh user@hostname [command] where command is "df -k /dev/md/dsk/d10 | tail -1"

This is the easier way, no need to use expect..

ghostdog74

Your solution does not address the fact that I will need to send out several commands, once I get it to work. I also need expect, in order to send out the password.

'...does a few checks and sends the results to a file.'

Tony