Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Hi all, I want to run a set of commands in bash file, one of them is the following: Code: ssh root [atsing]192.168.122.193 'echo s2 >> /home/guest/Desktop/upload/app.txt' But I want ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11

    entering pasword in bash file


    Hi all,

    I want to run a set of commands in bash file, one of them is the following:
    Code:
    ssh root [atsing]192.168.122.193 'echo s2 >> /home/guest/Desktop/upload/app.txt'
    But I want to also enter password in the bash file, how can I do that?

    Any help is appreciated.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,229
    This could be done via expect instead of bash.

    However, my recommendation is to not go this way as it will leave sensitive information unprotected.
    My suggestion is to setup ssh key authentication together with ssh-agent instead.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11
    Thanks. Could you please explain how to use expect? I search I tried a few things, but unsuccessful.
    And it is not sensitive, from a virtual machine I am ssh ing to another one just for some experiments.

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,229
    Here is a simple example, that you can modify for your needs
    SSH login expect shell script to supply username and password
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11
    The script I'm trying to use is the following:

    Code:
    #!/usr/bin/expect -f
    ssh root@192.168.122.193
    expect "expect "*?assword:*"
    send -- "1234\r"
    send -- "\r"
    interact
    but it does not work, still I should enter password.

  6. #6
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,229
    You need to spawn ssh
    You must always face the curtain with a bow.

  7. #7
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11
    Without spawn, ssh command is executed and I get the message to enter pass.
    This is what I'm using now:
    Code:
    #!/usr/bin/expect 
    spawn ssh root@192.168.122.193
    expect "*?assword:*"
    send -- "vm1234\r"
    send -- "\r"
    expect eof
    But Nothing is shown in command line after contrl+c I got:
    Code:
    ^Ccouldn't read file "*?assword:*": no such file or directory
    a.sh: line 4: send: command not found
    a.sh: line 5: send: command not found
    couldn't read file "eof": no such file or directory
    Last edited by sanaz; 02-07-2013 at 08:43 PM.

  8. #8
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,229
    spawn needs to be used.
    But you have a syntax error in the expect line.
    You must always face the curtain with a bow.

  9. #9
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11
    Now I have :
    Code:
    ^Ccouldn't read file "*?assword:*": no such file or directory
    a.sh: line 4: send: command not found
    a.sh: line 5: send: command not found
    couldn't read file "eof": no such file or directory

  10. #10
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,229
    Please dont modify posts after a response, this is confusing.

    It seems, bash is executing this script instead of expect.
    Is expect installed?
    The script should be executeable, and then just called. e.g.: ./test.tcl
    For clarity reasons, the suffix should be .tcl instead of .sh.
    You must always face the curtain with a bow.

Page 1 of 2 1 2 LastLast

Posting Permissions

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