public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* automate SSH-HOST-CONFIG
@ 2009-01-10  5:29 blazt
  2009-01-10 11:53 ` Dmitry Semyonov
  2009-01-13  2:31 ` blazt
  0 siblings, 2 replies; 8+ messages in thread
From: blazt @ 2009-01-10  5:29 UTC (permalink / raw)
  To: cygwin


How can I automate this process? If I do a ssh-host-config -y it works fine
all the way up to asking about the privileged account. I want to use this
account and can add the password to the command line parameter but how can I
answer yes for the first part but no when it comes to this question?

Thanks
-- 
View this message in context: http://www.nabble.com/automate-SSH-HOST-CONFIG-tp21383170p21383170.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automate SSH-HOST-CONFIG
  2009-01-10  5:29 automate SSH-HOST-CONFIG blazt
@ 2009-01-10 11:53 ` Dmitry Semyonov
  2009-01-13  2:31 ` blazt
  1 sibling, 0 replies; 8+ messages in thread
From: Dmitry Semyonov @ 2009-01-10 11:53 UTC (permalink / raw)
  To: cygwin

On Sat, Jan 10, 2009 at 03:34, blazt wrote:

> How can I automate this process?

Create 'expect' script. You'll likely have to update it here and there
after ssh-host-config upgrades though.

-- 
...Bye..Dmitry.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automate SSH-HOST-CONFIG
  2009-01-10  5:29 automate SSH-HOST-CONFIG blazt
  2009-01-10 11:53 ` Dmitry Semyonov
@ 2009-01-13  2:31 ` blazt
  2009-01-13  9:45   ` Dmitry Semyonov
  1 sibling, 1 reply; 8+ messages in thread
From: blazt @ 2009-01-13  2:31 UTC (permalink / raw)
  To: cygwin


I am not sure how to do a except script. I have been looking at what I can
find on the net. Would I pass this command into the except part?




blazt wrote:
> 
> How can I automate this process? If I do a ssh-host-config -y it works
> fine all the way up to asking about the privileged account. I want to use
> this account and can add the password to the command line parameter but
> how can I answer yes for the first part but no when it comes to this
> question?
> 
> Thanks
> 

-- 
View this message in context: http://www.nabble.com/automate-SSH-HOST-CONFIG-tp21383170p21427082.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automate SSH-HOST-CONFIG
  2009-01-13  2:31 ` blazt
@ 2009-01-13  9:45   ` Dmitry Semyonov
  2009-01-13 19:21     ` blazt
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Semyonov @ 2009-01-13  9:45 UTC (permalink / raw)
  To: cygwin

Hi Johnny,

On Tue, Jan 13, 2009 at 03:28, blazt wrote:
>
> I am not sure how to do a except script. I have been looking at what I can
> find on the net.

It is 'expect', not 'except'. It's enough to read 'man expect' for basics.
You'll have to learn some Tcl docs for advanced usage, (not required
for ssh-host-config automation).


> Would I pass this command into the except part?

See an excerpt from my expect script below. I don't provide the full
version, as it is complicated more than necessary for the
demonstration due to support of different OSes and corner cases. (Also
it was not verified with the latest ssh-host-config.)


#!/bin/expect -f

# required on Win2k3
exec chmod +r /etc/passwd
exec chmod +r /etc/group
exec chmod +x /var

spawn ssh-host-config

# Host keys generation is lengthy procedure
set timeout 20

expect {
  "Overwrite existing /etc/ssh_config file? (yes/no)" { send "yes\r";
exp_continue }
  "Overwrite existing /etc/sshd_config file? (yes/no)" { send "yes\r";
exp_continue }
  "Should privilege separation be used? (yes/no)" { send "yes\r" }
}

set timeout 5

expect {
  "Should this script create a local user 'sshd' on this machine?
(yes/no)" { send "yes\r" }
  "new local account 'sshd'? (yes/no)" { send "yes\r" }
}

# [skipped]

expect eof { exec cygrunsrv -S sshd }


-- 
...Bye..Dmitry.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automate SSH-HOST-CONFIG
  2009-01-13  9:45   ` Dmitry Semyonov
@ 2009-01-13 19:21     ` blazt
  2009-01-16  2:20       ` Dmitry Semyonov
  0 siblings, 1 reply; 8+ messages in thread
From: blazt @ 2009-01-13 19:21 UTC (permalink / raw)
  To: cygwin


Hi Dimitri, thanks for your help.

I created the script based on yours but it never sends the expect back to
the program.

#!/bin/bash
#!./expect -f 
chmod +r /etc/passwd
chmod +r /etc/group
chmod +x /var

echo "Starting Script"

ssh-host-config 
# Host keys generation is lengthy procedure
set timeout 20

expect {
  "*** Query: Overwrite existing /etc/ssh_config file? (yes/no)" { send
"yes\r";
exp_continue }
  "Overwrite existing /etc/sshd_config file? (yes/no)" { send "yes\r";
exp_continue }
  "Should privilege separation be used? (yes/no)" { send "yes\r" 
exp_continue}
  "Say "no" if it is already installed as a service) (yes/no)" { send
"yes\r"
exp_continue}
  "Enter the value of CYGWIN for the daemon: [ntsec]" { send "\r"
exp_continue}
  "Do you want to use a different name? (yes/no) " { send  "no\r"
exp_continue}
  "Please enter the password for user 'cyg_server':" { send "password\r"
exp_continue}
  "Reenter: " { send "password" }
} 

echo "end First Part"
set timeout 5 

expect {
  "Should this script create a local user 'sshd' on this machine?
(yes/no)" { send "yes\r" }
  "new local account 'sshd'? (yes/no)" { send "yes\r" }
}

I took out the exec so I could see the script run and it simply hangs at the
first query where it asks to overwrite existing files. Is there anything
else I need to do to get this to work with cygwin?




Dmitry Semyonov-2 wrote:
> 
> Hi Johnny,
> 
> On Tue, Jan 13, 2009 at 03:28, blazt wrote:
>>
>> I am not sure how to do a except script. I have been looking at what I
>> can
>> find on the net.
> 
> It is 'expect', not 'except'. It's enough to read 'man expect' for basics.
> You'll have to learn some Tcl docs for advanced usage, (not required
> for ssh-host-config automation).
> 
> 
>> Would I pass this command into the except part?
> 
> See an excerpt from my expect script below. I don't provide the full
> version, as it is complicated more than necessary for the
> demonstration due to support of different OSes and corner cases. (Also
> it was not verified with the latest ssh-host-config.)
> 
> 
> #!/bin/expect -f
> 
> # required on Win2k3
> exec chmod +r /etc/passwd
> exec chmod +r /etc/group
> exec chmod +x /var
> 
> spawn ssh-host-config
> 
> # Host keys generation is lengthy procedure
> set timeout 20
> 
> expect {
>   "Overwrite existing /etc/ssh_config file? (yes/no)" { send "yes\r";
> exp_continue }
>   "Overwrite existing /etc/sshd_config file? (yes/no)" { send "yes\r";
> exp_continue }
>   "Should privilege separation be used? (yes/no)" { send "yes\r" }
> }
> 
> set timeout 5
> 
> expect {
>   "Should this script create a local user 'sshd' on this machine?
> (yes/no)" { send "yes\r" }
>   "new local account 'sshd'? (yes/no)" { send "yes\r" }
> }
> 
> # [skipped]
> 
> expect eof { exec cygrunsrv -S sshd }
> 
> 
> -- 
> ...Bye..Dmitry.
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/automate-SSH-HOST-CONFIG-tp21383170p21442493.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automate SSH-HOST-CONFIG
  2009-01-13 19:21     ` blazt
@ 2009-01-16  2:20       ` Dmitry Semyonov
  2009-01-16  3:01         ` blazt
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Semyonov @ 2009-01-16  2:20 UTC (permalink / raw)
  To: cygwin

On Tue, Jan 13, 2009 at 22:16, blazt wrote:

> I created the script based on yours but it never sends the expect back to
> the program.
>
> #!/bin/bash

This line was not included into my sample. I doubt it can work this way.

> #!./expect -f

Why the dot-slash? Do you have expect executable in your local
directory? Have you compiled it by yourself?
'expect' package could be installed through Cygwin setup. You should
use this method instead.

 [...]

> I took out the exec so I could see the script run and it simply hangs at the
> first query where it asks to overwrite existing files. Is there anything
> else I need to do to get this to work with cygwin?

If you don't have enough experience don't make unnecessary changes or
add your bits before ensuring that the provided sample works. Read the
man. Experiment with simple things.

-- 
...Bye..Dmitry.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automate SSH-HOST-CONFIG
  2009-01-16  2:20       ` Dmitry Semyonov
@ 2009-01-16  3:01         ` blazt
  2009-01-16 21:02           ` blazt
  0 siblings, 1 reply; 8+ messages in thread
From: blazt @ 2009-01-16  3:01 UTC (permalink / raw)
  To: cygwin


Thank you Dimitri. It was my bin bash that cuased it to not work. I was not
aware that I did not have to include that. Once I fixed that and put things
back. it worked.

Thank you



Dmitry Semyonov-2 wrote:
> 
> On Tue, Jan 13, 2009 at 22:16, blazt wrote:
> 
>> I created the script based on yours but it never sends the expect back to
>> the program.
>>
>> #!/bin/bash
> 
> This line was not included into my sample. I doubt it can work this way.
> 
>> #!./expect -f
> 
> Why the dot-slash? Do you have expect executable in your local
> directory? Have you compiled it by yourself?
> 'expect' package could be installed through Cygwin setup. You should
> use this method instead.
> 
>  [...]
> 
>> I took out the exec so I could see the script run and it simply hangs at
>> the
>> first query where it asks to overwrite existing files. Is there anything
>> else I need to do to get this to work with cygwin?
> 
> If you don't have enough experience don't make unnecessary changes or
> add your bits before ensuring that the provided sample works. Read the
> man. Experiment with simple things.
> 
> -- 
> ...Bye..Dmitry.
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/automate-SSH-HOST-CONFIG-tp21383170p21490305.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automate SSH-HOST-CONFIG
  2009-01-16  3:01         ` blazt
@ 2009-01-16 21:02           ` blazt
  0 siblings, 0 replies; 8+ messages in thread
From: blazt @ 2009-01-16 21:02 UTC (permalink / raw)
  To: cygwin


Here is the complete script for anyone in the future. There was some odd
stuff that this did until I got it worked out. This is for a brand new
install of cygwin on a box that has never been used before. I am sure 
someone can possibly edit this so that it can select from a different number
of expect statements in case a user has installed cygwin before and is now
doing a reinstall.

#!/bin/expect -f

# required on Win2k3
exec chmod +r /etc/passwd
exec chmod +r /etc/group
exec chmod +x /var

spawn ssh-host-config

# Host keys generation is lengthy procedure
set timeout 20

expect {
  "Should privilege separation be used? (yes/no)" { send "yes\r" }
} 

set timeout 5

expect {
  "Note that creating a new user requires that the current account have" {
send "yes\r";
exp_continue }
  "Do you want to install sshd as a service?" { send "yes\r";
exp_continue }
  "Enter the value of CYGWIN for the daemon:" { send " \r"; }
}

set timeout 5

expect {
 "Do you want to use a different name? (yes/no)" { send "no\r"; 
exp_continue }
 "Create new privileged user account" { send "yes\r"; 
exp_continue }
 "Please enter" { send "pwd\r";
exp_continue }
 "Reenter:" {send "pwd\r";
exp_continue }
}







blazt wrote:
> 
> Thank you Dimitri. It was my bin bash that cuased it to not work. I was
> not aware that I did not have to include that. Once I fixed that and put
> things back. it worked.
> 
> Thank you
> 
> 
> 
> Dmitry Semyonov-2 wrote:
>> 
>> On Tue, Jan 13, 2009 at 22:16, blazt wrote:
>> 
>>> I created the script based on yours but it never sends the expect back
>>> to
>>> the program.
>>>
>>> #!/bin/bash
>> 
>> This line was not included into my sample. I doubt it can work this way.
>> 
>>> #!./expect -f
>> 
>> Why the dot-slash? Do you have expect executable in your local
>> directory? Have you compiled it by yourself?
>> 'expect' package could be installed through Cygwin setup. You should
>> use this method instead.
>> 
>>  [...]
>> 
>>> I took out the exec so I could see the script run and it simply hangs at
>>> the
>>> first query where it asks to overwrite existing files. Is there anything
>>> else I need to do to get this to work with cygwin?
>> 
>> If you don't have enough experience don't make unnecessary changes or
>> add your bits before ensuring that the provided sample works. Read the
>> man. Experiment with simple things.
>> 
>> -- 
>> ...Bye..Dmitry.
>> 
>> --
>> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>> Problem reports:       http://cygwin.com/problems.html
>> Documentation:         http://cygwin.com/docs.html
>> FAQ:                   http://cygwin.com/faq/
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/automate-SSH-HOST-CONFIG-tp21383170p21505830.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-01-16 18:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-10  5:29 automate SSH-HOST-CONFIG blazt
2009-01-10 11:53 ` Dmitry Semyonov
2009-01-13  2:31 ` blazt
2009-01-13  9:45   ` Dmitry Semyonov
2009-01-13 19:21     ` blazt
2009-01-16  2:20       ` Dmitry Semyonov
2009-01-16  3:01         ` blazt
2009-01-16 21:02           ` blazt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).