Results 1 to 4 of 4

Thread: ssh login script

  1. #1
    Join Date
    Nov 2010
    Location
    Kerala
    Beans
    376
    Distro
    Ubuntu

    ssh login script

    HI feed up with this topic of ssh login for taking backup automatically I got a expect script which will closed with out server's shell .please any one help me to correct this scrip


    #!/usr/bin/expect
    set timeout 9
    set username [lindex $argv 0]
    set password [lindex $argv 1]
    set hostname [lindex $argv 2]
    log_user 0
    if {[llength $argv] == 0}
    { send_user "Usage: scriptname username \'password\' hostname\n" exit 1 }
    send_user "\n#####\n# $hostname\n#####\n"
    spawn ssh -q -o StrictHostKeyChecking=no $username@$hostname
    expect { timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
    eof { send_user "\nSSH failure for $hostname\n"; exit 1 } "*assword" }
    send "$password\r"
    expect { timeout { send_user "\nLogin failed. Password incorrect.\n"; exit 1} "*\$ " }
    send_user "\nPassword is correct\n"
    send "exit\r"
    close


    I compiling this script it show that passed is correct and I cant get into server terminal I need to back up mysql file every day I usually use ""ssh koha@ip and scp -r backup/ remoteuser@ipaddress:~/ ""

    some times I forget to take whole this thats why I am again here with this topic , expecting a kind full help form all masters that use this world


    Thanks
    Last edited by Rakeshvijayan; March 5th, 2013 at 11:06 AM.
    you can learn what is computer ubuntu is the best way .I start learning ubuntu in 2-1-2010 .start with UBUNTU 9 now using 12.04

  2. #2
    Join Date
    Nov 2008
    Location
    Lleida, Spain
    Beans
    1,157
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: ssh login script

    Are you using expect only for login purposes? Why don't you use your ssh public key for autologin?

  3. #3
    prodigy_ is offline May the Ubuntu Be With You!
    Join Date
    Mar 2008
    Beans
    1,219

    Re: ssh login script

    Quote Originally Posted by Rakeshvijayan View Post
    Code:
    set username [lindex $argv 0]
    set password [lindex $argv 1]
    set hostname [lindex $argv 2]
    What's the point of scripting if you enter hostname and credentials manually anyway? You could as well use ssh username@hostname and type your password when prompted.

    Or if you call expect from another script, you could use something much simpler like the following stock example from Wikipedia:
    Code:
    spawn ssh $user@machine
    while {1} {
      expect {
     
        eof                          {break}
        "The authenticity of host"   {send "yes\r"}
        "password:"                  {send "$password\r"}
        "*\]"                        {send "exit\r"}
      }
    }
    wait
    close $spawn_id
    Last edited by prodigy_; March 5th, 2013 at 01:07 PM.

  4. #4
    Join Date
    Nov 2010
    Location
    Kerala
    Beans
    376
    Distro
    Ubuntu

    Re: ssh login script

    finaly I fedup this topic I cant able to make this one


    Thanks friends for the valuable time
    you can learn what is computer ubuntu is the best way .I start learning ubuntu in 2-1-2010 .start with UBUNTU 9 now using 12.04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •