Expect Script - error using sed -


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect Script - error using sed -
# 1  
Old 10-12-2006
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
tony3101
# 2  
Old 10-12-2006
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
# 3  
Old 10-12-2006
I dont have a problem with ssh.

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

Tony
tony3101
# 4  
Old 10-12-2006
Quote:
Originally Posted by tony3101
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..
# 5  
Old 10-12-2006
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
tony3101
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script error : send: spawn id exp4 not open

Hi, I am executing a expect script in while loop for doing telnet on list of servers stored in file as below : expect script : #!/usr/bin/expect -f set timeout 20 set ip set port if { == 0} { send_user "Usage: scriptname ip port\n" exit 1 } #exp_internal 1 log_user 0 spawn... (3 Replies)
Discussion started by: omkar.jadhav
3 Replies

2. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

3. Shell Programming and Scripting

EXPECT Bash Script Error Control

Hello Geeks once more, Thanks for all the help you have been rendering.. I have a script that depends on the output of an expect statement but sometimes the main script misbehaves which I believe is a result of SSH communication error, how can I apply an error control to know whether the... (2 Replies)
Discussion started by: infinitydon
2 Replies

4. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

5. Shell Programming and Scripting

'Couldn't read file' error in bash script with expect, sed and awk!

Ok, so I have a bash script with an embedded expect statement. Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time. Here's my command: cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies

6. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

7. Shell Programming and Scripting

Expect Script Error Handling

Good Day Everyone, I was hoping to get a little insight into an expect script that I've written. Basically we have this expect script to perform an sftp upload, key authentication is not an option, and sftp is the only method supported by our vendor, thus the need for this. I want to be... (3 Replies)
Discussion started by: thaller
3 Replies

8. Shell Programming and Scripting

Expect Script Error invalid spawn id (6)

Hi everybody, We are trying to connect to a server and to a router using an .expect script that automatically authenticate the username and password needed. The error is that we cannot connect to the server using ssh AND we cannot connect to the router using either telnet or go commands from the... (1 Reply)
Discussion started by: omoyne
1 Replies

9. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

10. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies
Login or Register to Ask a Question