Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an expect script which checks if a file exists on a remote server and then tries to print ( using cat) it if it does

For some reason the expect script ignores these commands.

send "if {[file exists "./abc.test"]} {cat ./abc.txt\r}"
share|improve this question

3 Answers 3

I have never used Expect, but your code sample...

if {[file exists "./abc.test"]} {send "cat ./abc.txt\r"}

...seems to check for file existence on the machine expect runs on, not the remote one. So unless the script is being run on the remote server, it won't work.

share|improve this answer
up vote 1 down vote accepted

Here is what I did and it worked now

cat /some/path/abc.txt 2> /dev/null

This way, the file gets printed if it exists and does not throw an error if it doesn't.

share|improve this answer

Hm, you're probably doing things in a rather roundabout way.

First, please describe your context:

  • Exactly how (complete command line) do you invoke this script?
  • How does it access the remote server? There is no remote access in the script you provide.

Finally, what are you really trying to do? If you want to print a file on a remote system, it's probably easier to directly invoke ssh. Expect is meant for scripting programs which do not have a scripting language (such as simple ftp clients). It's needlessly complicated to use it with a command shell, which already has a powerful scripting language.

share|improve this answer
    
I use a bash script to invoke the expect script (for automated login ).I need to do some checks on a list of remote servers and the code snippet I mentioned above is one of those checks I have put in the expect script. –  Sharjeel Sayed Aug 6 '09 at 8:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.