LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-31-2009, 01:45 PM   #1
edomingox
Member
 
Registered: Mar 2009
Posts: 49

Rep: Reputation: 15
My "expect" script is not working... Won't "send" commands...


I've been working on this script for hours trying to figure out why it's not working. The following code is a portion of the whole script. This code is actually within a "for" loop. here's the code:
Code:
                set timeout 3
		spawn -noecho ssh ${account}@$ipAddress 
		send_user "Configuring $equipment...\n"
		log_user 0
		# LOOKING FOR THE PASSWORD PROMPT
		expect {
			"yes/no" {
				send "yes\r"
				exp_continue
			}
			"*?assword:*$" {
				send "$pass\r"
			}
			timeout {
				set error "$equipment $ipAddress is unreachable\n"
				set passLog "$passLog$error"
				continue
			}
		}
	
		# LOOKING FOR THE PROMPT
		expect {
			"#" {
				send "ls\r"	
				log_user 1
				send_user "Working...\n"
				send "exit\r"
				send_user "Working2...\n"
				
			}
			"Permission denied" {
				set error "Wrong Password for $equipment $ipAddress using user \"$account\".\n"
				set passLog "$passLog$error"
				continue
			}
		}
The script was made to ensure a clean login is made and report any unreachable ip addresses or bad password inputs.

My greatest concern lies within the expected "#" portion. The lines with "Working..." and "Working2..." both display. So it seems to be bypassing my "send ls/r" and the "send exit/r". I don't know why it's doing that. Any help would be great.
 
Old 03-31-2009, 02:18 PM   #2
kenoshi
Member
 
Registered: Sep 2007
Location: SF Bay Area, CA
Distribution: CentOS, SLES 10+, RHEL 3+, Debian Sarge
Posts: 159

Rep: Reputation: 32
make sure you insert:

Code:
expect eof
After you send "exit" to the remote shell. Either that or go interactive.

Hope this helps.
 
Old 04-01-2009, 08:15 AM   #3
edomingox
Member
 
Registered: Mar 2009
Posts: 49

Original Poster
Rep: Reputation: 15
my biggest concern is when I'm trying to do the "send ls\r" and it doesn't work. I don't really want to exit the script in there because it's in a loop. I only added the exit to see if that it actually does exit, but it doesn't. I think I may have some syntax or something wrong.

edit: I tried expect eof after the send ls and that worked. thanks for the help. i'll have to read up on why it's done this way as i wasn't really expecting it to run like that.

Last edited by edomingox; 04-01-2009 at 02:36 PM.
 
Old 04-01-2009, 09:29 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,087

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Did you put set exp_internal 1 at the beginning of your code?

jlinkels
 
Old 04-02-2009, 03:25 PM   #5
edomingox
Member
 
Registered: Mar 2009
Posts: 49

Original Poster
Rep: Reputation: 15
I havent tried doing that yet. But I figured out that the script was getting ahead of itself. So the expect eof helped that out. I'll test that out too. Just to see what it shows me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 10:35 AM
net working eth0 eth1 wlan0 "no connection" "no LAN" "no wi-fi" Cayitano Linux - Newbie 5 12-09-2007 07:11 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
commands "init" and "modprobe" not working Diagmato Fedora 2 07-22-2005 11:44 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM


All times are GMT -5. The time now is 09:35 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration