OESF Portables Forum

General Forums => General Discussion => Topic started by: Soapy-J on May 28, 2004, 05:34:09 pm

Title: Automating SSH...
Post by: Soapy-J on May 28, 2004, 05:34:09 pm
Hi

I\'d like to be able to automate some interactive shell type things on my Zaurus. I\'d like to run a single script to say, log me in via ssh to a linux host and run up a mail client, without having to type my long password in on the Zaurus keyboard.

I guess this is a bit of a general automation issue, but I\'m interested to see whether any other Zaurus users have tried to implement the above, and what their experiences have been.

Thanks

Soapy-J
Title: Automating SSH...
Post by: Anonymous on May 28, 2004, 06:07:05 pm
Try Expect.  You can automate any text application with Expect.  ora.com has the only and best book on it.

http://sense.net/zc/files (http://sense.net/zc/files) to download.  You\'ll need tcl as well.

There is also python expect for the Z.  Not a fan of python (or tcl), but tcl is quick and easy.

I\'ll post a sample later.
Title: Automating SSH...
Post by: cmisip on May 28, 2004, 06:59:29 pm
I dont know if this is what you want but you can configure ssh to be passwordless and run remote commands using scripts that way.
Title: Automating SSH...
Post by: pmf on May 29, 2004, 01:15:31 am
Quote
I\'d like to be able to automate some interactive shell type things on my Zaurus. I\'d like to run a single script to say, log me in via ssh to a linux host and run up a mail client, without having to type my long password in on the Zaurus keyboard.


You want SSH Public Key authentication (http://www.noah.org/ssh/publickey/).

Basically: instead of having to type your password each time, you will have to generate a secret key for the local host (your Zaurus) and the corresponding public key for the remote host.

Generate both keys on the Zaurus with
Code: [Select]
ssh-keygen -t rsa.

They will be in ~/.ssh

Copy ~/.ssh/id_rsa.pub to the remote host (your PC) and append it to ~/.ssh/authorized_keys.
Like this (on the remote host):
Code: [Select]
cat id_rsa.pub >> authorized_keys
Title: Automating SSH...
Post by: Soapy-J on May 31, 2004, 01:15:41 pm
Cmisip and pmf, Thanks for the tips!

Public key authentication access for SSH, and maybe I can use expect for some tasks on the linux host (ie those pesky interactive ones that I hadn\'t even tried to script before!)

Cheers!

Soapy-J
Title: Automating SSH...
Post by: cmisip on May 31, 2004, 11:34:14 pm
Here\'s how I setup to execute scripts that work on the remote machine.  You can even emulate keyboard presses.  Check the section about passwordless ssh.

http://cmisip.home.insightbb.com/advanced.htm (http://cmisip.home.insightbb.com/advanced.htm)
Title: Automating SSH...
Post by: cmisip on June 01, 2004, 12:59:16 am
Once you have setup your ssh this way, emulate a \"ghost\" in the pc.  If there is an open text editor on the remote pc do this

 echo \"Help-I-am-inside-this-computer.-Let-me-out.\" | xargs ssh user@remotepc \"export DISPLAY=localhost:0; /usr/X11R6/bin/xvkbd -text \"
Title: Automating SSH...
Post by: datajerk on June 01, 2004, 02:01:36 pm
Below is the code I said that I\'d post.  As you can see from the previous posts there is more that one way to do it.  I use ssh key auth as well for non-interactive scripts (e.g. VPN setup), however it can be difficult to script interactive tty-based applications.  For that I use expect.

The script below takes one arg (passwd), sshes to my ISP and forwards ports 25, 110, and 8080.  I do this because some WiFi locations have port 80 blocked so I need a proxy and my ISP requires SSL or SSH for mail.  Since the Z mail app does not  use SSL I just forward 25 and 110 and have the Z mail app point to localhost.

After I connect expect starts elm and then drops in to interact mode.  You can do a lot in interact mode and have it watch for characters in both directions and automate many functions for you.  Below expect is watching for EOF (ssh exit) or ~. to exit.  If the keys \"DS\" are pressed then it sends ^DSPAM:[return] to delete all spam from elm.

This is a common procedure for me since ]90% of my mail is SPAM and downloading mail to the Z app over GPRS is slow enough.  I could have just sent the ^DSPAM:[return] to elm, exited elm then started interact at the prompt, but I like to take a quick look at the headers for false positives.  Then I hit the DS, q to quit, y to delete, y to save in inbox, then use Z mail to download mail for offline reading.

You can get expect from http://sense.net/zc/files (http://sense.net/zc/files) (they are ipk of the standard debian .deb files).  Get the tcl package as well.

The book: http://www.oreilly.com/catalog/expect/index.html (http://www.oreilly.com/catalog/expect/index.html)

Code: [Select]
#!/usr/bin/expect



log_user 0



set passwd [lindex $argv 0]



spawn ssh -g -l me -L 25:localhost:25 -L 110:localhost:110 -R 8080:proxy.myisp.com:8080 myisp.com



expect {

  "word: " {

    send "$passwdr"

    expect {

      "Permission denied" {

        puts "bad password"

        exit 1

      }

      "$" {

        send "elmr"

        interact {

          "DS" {

            send "\004SPAM:r"

          }

          "~." {

            exit 0

          }

          EOF {

            exit 0

          }

        }

      }

    }

  }

  timeout {

    puts "Timeout"

    exit 1

  }

  "ssh:*" {

    puts "$expect_out(0,string)"

    exit 1

  }

}
Title: Automating SSH...
Post by: Anonymous on June 18, 2004, 12:23:42 pm
expect isnt really what you want, ssh key based authentication is all you need,

have a look here :- http://www.cs.umd.edu/~arun/misc/ssh.html (http://www.cs.umd.edu/~arun/misc/ssh.html)