Welcome to the Linux Foundation Forum!

getting remote output with expect

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?

Comments

  • 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 [email protected]
    
    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).
  • amnesiaamnesia Posts: 60
    I agree.

    download @ http://www.openssh.org/portable.html 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/id_rsa.pub [email protected] (for each individual hosts)

    ssh into the first machine
    cat ~/id_rsa.pub >> ~/.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
    192.168.1.1
    192.168.1.2
    192.168.1.3 and so on

    now,
    for i in `cat hosts.dat`; do ssh [email protected]$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
  • 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
  • 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)
Sign In or Register to comment.