LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-17-2010, 08:50 AM   #1
mikejreading
LQ Newbie
 
Registered: May 2009
Posts: 24

Rep: Reputation: 0
Expect problem


Guys,

Just a quick query... I may be being a bit thick!!

I have written an expect script... see code:

Code:
#!/usr/bin/expect
set add1 [lindex $argv 0]
spawn ssh ${add1} -l mike
expect *assword:
send "PASSWORD123\r"
expect ]$
send "free -k > freemem${add1}\r"
expect ]$
send "chmod 777 freemem${add1}\r"
expect ]$
send "df -h > freedisk${add1}\r"
expect ]$
send "chmod 777 freedisk${add1}\r"
expect eof
exit
This takes FOREVER to run... something I am doing wrong, perhaps???

Cheers
Mike
 
Old 11-17-2010, 09:27 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

The 'expect eof' at the end will never happen, because you don't exit out of the shell and close the connection.
Try:
Code:
[snip]
expect ]$
send "chmod 777 freedisk${add1}\r"
expect ]$
send exit
expect eof
exit

Dave
 
Old 11-17-2010, 12:17 PM   #3
mikejreading
LQ Newbie
 
Registered: May 2009
Posts: 24

Original Poster
Rep: Reputation: 0
Thanks... will try that aswell, that should stop the timeout which seems to happen at the end.... can you think of any reason why it takes so long to send the other commands?

They seem wait for a while before they run the next command.

Everything works - just takes AGES!
 
Old 11-17-2010, 12:24 PM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Ah.

You're probably not matching on 'expect ]$' - the expect is most likely timing out. Can you check that your prompt really does have ']$' in it. and not maybe '] $'? If it's OK, I'd try quoting the expect line like:
Code:
expect "]$"
Dave
 
Old 11-17-2010, 12:35 PM   #5
mikejreading
LQ Newbie
 
Registered: May 2009
Posts: 24

Original Poster
Rep: Reputation: 0
Good shout. It was a space that was missing.

Sorry - I did open with the face that I was probably being thick

Cheers
Mike
 
  


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
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
expect: line seems to match exactly, however expect thinks not deadeyes Linux - General 5 06-16-2010 06:05 PM
Problem with expect utility saileshg9379 Linux - Newbie 3 04-15-2009 01:50 PM
expect problem john83reuben Programming 5 07-30-2008 06:35 AM
problem in expect john83reuben Programming 1 07-16-2008 06:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:13 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration