Need help with output from 'do script'

I am trying to get output from an ls of a remote system that I need to telnet into. No, ssh can’t work to hide the password in the Keychain. I’m building an application, and it needs to be portable between machines.

My problem is that I need to telnet in, pass a password, enter a command to get to a prompt, then do the ls command. If I use ‘do script’, it gives no return. I think this is due to the AS specs on the command. However, if I use a ‘do shell script’, it doesn’t seem to get the ls from the remote system.

do script:
tell application “Terminal”
do script “rlogin -l user 19.17.18.10” in window 1
delay 3
do script “password” in window 1
delay 3
do script “1” in window 1
delay 3
set logFile to {do script “ls | grep jciu9000” in window 1}
end tell
–This gives a listing of the remote box in the Terminal window, but no return.

do shell script:
tell application “Terminal”
set logFile to (do shell script “rlogin -l user 19.17.18.10; sleep 2; echo password; sleep 2; echo 1; sleep 2; ls”)
end tell
–This, I think, logs in to the remote box, but the ls returns the local directory!

Anyone see any errors or know a better way?

Thanks,
Stu

If you want to use interactive command scripting, you need 10.3.

For info on how to do interactive command scripting:

man expect

Any articles showing examples of how to integrate expect with AS?

Do you use a do shell script, or can you get the info out of a do script?

How about a simple example of expect based on my above question?

Thanks,
Stu

I’m sorry for being so curt, I was in a hurry, so I was even more elliptical than usual.
If you take a look at Technical Note 2065 “do shell script in AppleScript” you’ll see this Q and A towards the bottom:

You can use “man expect” to find out how to create an expect script, or you could google “telnet expect script” and come up with things like this:
The Linux Gazette Answer Guy
I’m sorry that I can’t help you with scripting expect, it’s been years since I used it to control modem dial-up in Linux.
If you have any problems, reply and maybe we can work them out together.
Reading that Q and A gave me an idea, you could have a cron job on the remote computer that runs a script that pipes ls to a text file and use curl to download the text file. It would work if the remote machine was running a web or ftp server.

Dennis,

No need to apologize. You pointed me in a good direction. I had seen expect mentioned on Apple’s TIL but couldn’t find any articles on using it in applescript. It’s just that I can’t expect to give a valid return from a do shell script.

Here’s what I came up with:
do shell script ("rlogin -l user 169.137.168.190; sleep 2; expect “Password:”; send pass; expect “Please select one of the above (1-4):”; send “1”; send “ls | grep jciu9000” ")
but the
expect “Password:” (or just Password:)
returns
couldn’t read file “Password:”: no such file or directory

And you can’t get any return from a do script, even though it shows the result!

I need to just get the result of an ls from a remote HP box and/or display the log file for an end user to read. If there’s any other way, I’d be happy to hear about it.

Thanks,
Stu

Anyone know how to send a password after sending the telnet command in a do shell script? The do script works fine, but can’t get a return from it.

This doesn’t seem to work:

try
set scriptResult to do shell script ("rlogin -l user 169.137.168.190; ¬
sleep 1; ¬
echo password;¬
sleep 1; ¬
echo 1; ¬
sleep 1; ¬
ls -ltr | grep jciu9000`)
display dialog scriptResult
end try

but neither does just passing the password directly as a command

I know you said that you can’t use ssh, but perhaps you can, if all you need is to run one command. You would create a user that is limited to that one command. You would need access to the HP box, ideally physical access, to place the public keys of the connecting machines in the “authorized keys” directory in the .ssh directory on the HP box, and sshd needs to be running on that HP box. Using public keys doesn’t require a passphrase but isn’t as secure. This is why you would need to create a user that is limited to the single command. This is much more secure than telnet, though. See this article by Mike Bombich for how to set up remote administration:
Remote Administration/Backup of Mac OS X Using rsync
It’s about using rsync, but will work with any command.