Home Linux Community Forums Software Command Line getting remote output with expect

getting remote output with expect

Link to this post 15 Aug 09

I'm working some embedded boxes with limited functionality. They run Linux(busybox shell). Its not fullfledged. only some of our custom code..

I need to reboot the box at times or run commands like top on it.

I tried my hands at using expect using simple expect, send, send_user sequences.

However, although I can login to the box, I cannot issue any other command once in.

I've tried to expect " # " thinking that it will wait for the # in the bash prompt and then send a command\r But doesnot help.

Can any one guide where I'm going wrong?

Link to this post 18 Aug 09

IF i understood your question, then you need openssh.

openssh has 2 parts: server and client. On the other boxes you have to run the server (make it to run on startup) and from your PC you have to run the client like:

ssh root@

where the IP is the IP of the remote computer, and root is the account you want to login.

there are great security options for openssh, look at the manual for that.

good luck and i hope you know the base bash commands (otherwise look at the Bash group at the community section).

Link to this post 18 Aug 09

I agree.

download @ if you don't have it

edit: if you're trying to execute a command on multiple machines
there's some neat little for loops you can do with ssh to make that happen

ssh-keygen -t rsa

scp ~/.ssh/ user@host (for each individual hosts)

ssh into the first machine
cat ~/ >> ~/.ssh/authorized_keys2
chmod 644 ~/.ssh/authorized_keys2

(do this for each machine)

now make a list on the workstation for each host
hosts.dat and so on

for i in `cat hosts.dat`; do ssh root@$i commands..; done

I have done this in the past -- It may need some tweaks or may not -- but if it's something that looks like what you want to do, its worth exploring

Link to this post 22 Aug 09

I know about SSH. and the box in question is not a computer. It is a Set-top-box. Since it is a box with a very limited footprint, SSH cannot be installed on it.

"expect" is what I expect to use over here..

"man 1 expect" for details on the expect interpreter

Link to this post 22 Aug 09

I did find a solution to my woes. I needed to use the interact command in order to execute the commands in the remote shell.

However now I cannot execute it if it is run from a cron..

nevermind thou, I found another solution to my original problem(which was taking snapshot of the device's memory)

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Linux Training / Board