LinuxQuestions.org
Help answer threads with 0 replies.
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 07-15-2008, 08:05 PM   #1
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Rep: Reputation: 17
problem in expect


HI, I have problem in ssh, im trying to connect to another server through expect program, and after conecting, ill change into a particular directory to check if a lock file exist.
Below i did a if statement to check if the file exist or not, but it not working, how to solve this problem. pls advice. thanks
Quote:


#!/projects/ilinterf/bin/expect

spawn /bin/ksh

set site "server1"




send "ssh -p 22 ilinterf@$site cd /projects/ilinterf/john/kul_john;ls -la john.lock\n"

expect "ls -la /projects/ilinterf/john/kul_john" {
if {file exist "/projects/ilinterf/john/kul_john/john.lock" == 1} {
send "exit"
expect "h>"
} else {
send "ls -la /projects/ilinterf/john/kul_john
expect "ls -la /projects/ilinterf/john/kul_john"
expect "h>"

}
 
Old 07-16-2008, 06:00 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
This is a very convoluted way to check for a file on a remote system. A simpler method which doesn't require expect at all if something like this:
Code:
#!/bin/ksh
result=$(ssh user@host '[ -a "/a/path/to/a/file" ] && echo yes || echo no')
At this point the variable result contains yes if the file exists, no if it does not, and will be blank if there was some connection error.

If you insist on using expect, I don't know why you spawn a ksh and then sending the ssh command to it - why not just spawn the ssh command?

Also, why are you expecting the command "ls -la /projects/ilinterf/john/kul_john"? This is not normal. The argument to expect is text you expect to see, not a command. You would typically expect a prompt or some other output which is produced during the login process, which is used as a trigger for sending some other command (in your case some test to see if a file exists).
 
  


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
Simple Expect problem.. please help :) cdwells Programming 2 07-30-2008 02:49 AM
problem receiving output from Expect script slinx Linux - Software 4 04-30-2008 08:02 AM
[Expect scripting] send problem ldp Programming 1 01-24-2005 02:39 PM
Expect: trivial problem with passwd mallouk Programming 2 05-19-2004 07:21 AM
Weird ISP problem: expect (#) weppnesp Linux - Newbie 0 10-06-2002 12:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:34 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