LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2009, 08:59 AM   #1
visu_kvg
LQ Newbie
 
Registered: Aug 2009
Location: HYD,India
Distribution: RHEL
Posts: 19

Rep: Reputation: 0
Execute a command using expect


Hello Guys,

I am new to Linux and LQ.

Well lets get into the business.

ssh user@remotehost ls /home/user
It produces the list of files on remotehost.Fine.

But I need to automise this using expect.
Well I have tried a bit as below

#!/bin/bash
echo $SHELL
/usr/bin/expect <<EOF
set timeout -1
spawn ssh user@remotehost ls /home/user
expect "password:"
send -- "password\r"

}


Script runs fine,but I am unable to get the expected O/P.

Please Guide me.

Last edited by visu_kvg; 08-05-2009 at 09:00 AM.
 
Old 08-05-2009, 09:03 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Have u tried autoexpect to do this, and using that expect script
 
Old 08-05-2009, 09:13 AM   #3
visu_kvg
LQ Newbie
 
Registered: Aug 2009
Location: HYD,India
Distribution: RHEL
Posts: 19

Original Poster
Rep: Reputation: 0
No man.Well how to do it?
 
Old 08-05-2009, 09:15 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
man autoexpect

It will record the the operation you are performing as an expect script. Try putting that expect script in your file.

Hope it works
 
Old 08-05-2009, 10:08 AM   #5
visu_kvg
LQ Newbie
 
Registered: Aug 2009
Location: HYD,India
Distribution: RHEL
Posts: 19

Original Poster
Rep: Reputation: 0
Great Man.It worked.
Thanks a lot....
 
  


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
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 12:51 AM
How to use expect command? jprathap Linux - Newbie 1 11-21-2008 10:30 PM
trying to execute an expect script in .bashrc smaudlin Red Hat 2 01-02-2005 01:34 AM
Automae telnet log in and execute commands (expect and send) rajatgarg Linux - Networking 0 06-24-2004 11:37 AM
using Expect command to automate prgms mehargags Linux - General 9 06-15-2003 07:16 PM


All times are GMT -5. The time now is 02:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration