LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Expect script - No output to file (https://www.linuxquestions.org/questions/programming-9/expect-script-no-output-to-file-553764/)

pandersson61 05-14-2007 09:58 AM

Expect script - No output to file
 
I'm using a expect script to connect to a mp3 server (irmp3d) via telnet and output a playlist. When i run the script from a bash shell the script works as expected and gets the playlist. But when i run the script from within the server all i get out of the script is the commands passed to the spawned telnet client. Does anyone have any idea on how to pipe the output from the telnet client to a file?

This is my script:
Quote:

#!/usr/bin/expect
log_file -a /home/mp3/telnet.log
set host [lindex $argv 0]
set port [lindex $argv 1]
spawn telnet $host $port
send "query plfiles\r"
send "exit\r"
When run through a regular bash shell the log looks something like this:
Quote:

220: plfiles: /music/Black Sabbath/Headless Cross/07-Black Moon.mp3
220: plfiles: /music/Black Sabbath/Headless Cross/08-Nightwing.mp3
But when i run the script through the mp3 server software all i get in the log is:
Quote:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
query plfiles
I have tried running the command:
Quote:

script 2%>1 /home/mp3/newlog.log
with the same results. Does anyone have any idea on how i can solve this? If so please let me know.

Thanks!

/Peter

twantrd 05-14-2007 12:32 PM

Quote:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
query plfiles
Ummm, are you sure you are connecting to the mp3 server? I'm seeing a connection to 127.0.0.1 - which is your own box.

-twantrd

pandersson61 05-14-2007 12:57 PM

Quote:

Originally Posted by twantrd
I'm seeing a connection to 127.0.0.1

Thanks for the reply!
The script is meant to be run on the server to save the current playlist on the server when the mp3 daemon is shut down. So the localhost ip is correct.
I have solved the problems by using the "script -c [script] /output/to/file.txt" command, for some reason that worked but not expect...

/Peter

lexwoodrum 05-21-2007 12:44 PM

Quote:

Originally Posted by pandersson61
Thanks for the reply!
The script is meant to be run on the server to save the current playlist on the server when the mp3 daemon is shut down. So the localhost ip is correct.
I have solved the problems by using the "script -c [script] /output/to/file.txt" command, for some reason that worked but not expect...

/Peter

When you telnet you have to enter the login ID and password.
You must send those from the expect program.

Since you did not, it just echos whatever you sent it.

lexwoodrum

pandersson61 05-23-2007 05:18 AM

Quote:

Originally Posted by lexwoodrum
When you telnet you have to enter the login ID and password.

Thanks for the reply! But the software running the telnet server doesn't require a login. You just telnet port 9232 (no username or password) and you get instant access. If i run the script from a normal bash shell the script works just fine. The problems occur when i run the script from inside the mp3 server software.

/Peter


All times are GMT -5. The time now is 11:46 AM.