teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

修正

2021/11/24 11:16

投稿

minhouse10
minhouse10

スコア41

title CHANGED
File without changes
body CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ip_file='systems.txt'
14
14
  USER='ohm'
15
- PASS='#!8102L#>t'
15
+ PASS='#xxxxxxxx'
16
16
  TARGET_DIR='test.txt'
17
17
  CR_DIR='/tmp/'
18
18
 

5

成功ログ

2021/11/24 11:16

投稿

minhouse10
minhouse10

スコア41

title CHANGED
File without changes
body CHANGED
@@ -132,4 +132,30 @@
132
132
  "ohm@22.222.22.222's password:"
133
133
  send "#!8102L#>t\n"
134
134
  }"
135
- [root@host]
135
+ [root@host]
136
+
137
+ ---------------
138
+ 修正版:成功!!
139
+
140
+ expect -c "
141
+ set timeout 5
142
+ spawn scp -v ${TARGET_DIR} ${USER}@${line}:${CR_DIR}
143
+ expect \"${USER}@${line}'s password:\" {
144
+ send \"${PASS}\n\"
145
+ }
146
+ expect \"${USER}@${line}'s password:\" {
147
+ send \"${PASS}\n\"
148
+ }
149
+ "
150
+
151
+ 結果:
152
+ Sending file modes: C0755 0 test.txt
153
+ Sink: C0755 0 test.txt
154
+ test.txt 100% 0 0.0KB/s 00:00
155
+ debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
156
+ debug1: channel 0: free: client-session, nchannels 1
157
+ debug1: fd 0 clearing O_NONBLOCK
158
+ debug1: fd 1 clearing O_NONBLOCK
159
+ Transferred: sent 2688, received 4328 bytes, in 0.1 seconds
160
+ Bytes per second: sent 25747.9, received 41457.1
161
+ debug1: Exit status 0

4

追記

2018/03/16 06:34

投稿

minhouse10
minhouse10

スコア41

title CHANGED
File without changes
body CHANGED
@@ -102,4 +102,34 @@
102
102
  debug1: Authentications that can continue: publickey,password,keyboard-interactive
103
103
  debug1: Next authentication method: password
104
104
 
105
- ohm@22.222.22.222's password: [root@host]#
105
+ ohm@22.222.22.222's password: [root@host]#
106
+
107
+ -----------
108
+ 修正後:
109
+ while read line || [ -n "${line}" ];
110
+ do
111
+ expect -c "
112
+ set timeout 5
113
+ spawn scp -v ${TARGET_DIR} ${USER}@${line}:${CR_DIR}
114
+ expect {
115
+ \"${USER}@${line}'s password:\"
116
+ send \"${PASS}\n\"
117
+ }
118
+ -re \"[Pp]assword:\" {
119
+ send \"${PASS}\n\"
120
+ }
121
+ interact
122
+ "
123
+ done < ${ip_file}
124
+
125
+ 結果:
126
+ debug1: Next authentication method: password
127
+ ohm@22.222.22.222's password: usage: send [args] string
128
+ while executing
129
+ "send"
130
+ invoked from within
131
+ "expect {
132
+ "ohm@22.222.22.222's password:"
133
+ send "#!8102L#>t\n"
134
+ }"
135
+ [root@host]

3

ログ追記

2018/03/16 06:21

投稿

minhouse10
minhouse10

スコア41

title CHANGED
File without changes
body CHANGED
@@ -100,4 +100,6 @@
100
100
  debug1: Trying private key: /root/.ssh/id_ed25519
101
101
  debug1: Next authentication method: keyboard-interactive
102
102
  debug1: Authentications that can continue: publickey,password,keyboard-interactive
103
- debug1: Next authentication method: password
103
+ debug1: Next authentication method: password
104
+
105
+ ohm@22.222.22.222's password: [root@host]#

2

ログの追加

2018/03/16 05:10

投稿

minhouse10
minhouse10

スコア41

title CHANGED
File without changes
body CHANGED
@@ -50,4 +50,54 @@
50
50
  }
51
51
  interact
52
52
  "
53
- ```
53
+ ```
54
+ scp -vオプションを付けて実行した結果になります。scpコマンドは実行されている事が確認。
55
+ [root@host]# bash scp_auto.sh
56
+ spawn scp -v test.txt ohm@22.222.22.222:/tmp
57
+ Executing: program /usr/bin/ssh host 22.222.22.222, user far, command scp -v -t /tmp
58
+ OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
59
+ debug1: Reading configuration data /etc/ssh/ssh_config
60
+ debug1: /etc/ssh/ssh_config line 56: Applying options for *
61
+ debug1: Connecting to 22.222.22.222 [22.222.22.222] port 22.
62
+ debug1: Connection established.
63
+ debug1: permanently_set_uid: 0/0
64
+ debug1: identity file /root/.ssh/id_rsa type -1
65
+ debug1: identity file /root/.ssh/id_rsa-cert type -1
66
+ debug1: identity file /root/.ssh/id_dsa type -1
67
+ debug1: identity file /root/.ssh/id_dsa-cert type -1
68
+ debug1: identity file /root/.ssh/id_ecdsa type -1
69
+ debug1: identity file /root/.ssh/id_ecdsa-cert type -1
70
+ debug1: identity file /root/.ssh/id_ed25519 type -1
71
+ debug1: identity file /root/.ssh/id_ed25519-cert type -1
72
+ debug1: Enabling compatibility mode for protocol 2.0
73
+ debug1: Local version string SSH-2.0-OpenSSH_6.6.1
74
+ debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2
75
+ debug1: match: OpenSSH_7.2 pat OpenSSH* compat 0x04000000
76
+ debug1: SSH2_MSG_KEXINIT sent
77
+ debug1: SSH2_MSG_KEXINIT received
78
+ debug1: kex: server->client aes128-ctr hmac-sha1 none
79
+ debug1: kex: client->server aes128-ctr hmac-sha1 none
80
+ debug1: kex: curve25519-sha256@libssh.org need=20 dh_need=20
81
+ debug1: kex: curve25519-sha256@libssh.org need=20 dh_need=20
82
+ debug1: sending SSH2_MSG_KEX_ECDH_INIT
83
+ debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
84
+ debug1: Server host key: RSA c2:ae:1e:70:c4:82:7e:21:49:36:5d:4a:29:6a:2d:a9
85
+ debug1: Host '22.222.22.222' is known and matches the RSA host key.
86
+ debug1: Found key in /root/.ssh/known_hosts:18
87
+ debug1: ssh_rsa_verify: signature correct
88
+ debug1: SSH2_MSG_NEWKEYS sent
89
+ debug1: expecting SSH2_MSG_NEWKEYS
90
+ debug1: SSH2_MSG_NEWKEYS received
91
+ debug1: Roaming not allowed by server
92
+ debug1: SSH2_MSG_SERVICE_REQUEST sent
93
+ debug1: SSH2_MSG_SERVICE_ACCEPT received
94
+
95
+ debug1: Authentications that can continue: publickey,password,keyboard-interactive
96
+ debug1: Next authentication method: publickey
97
+ debug1: Trying private key: /root/.ssh/id_rsa
98
+ debug1: Trying private key: /root/.ssh/id_dsa
99
+ debug1: Trying private key: /root/.ssh/id_ecdsa
100
+ debug1: Trying private key: /root/.ssh/id_ed25519
101
+ debug1: Next authentication method: keyboard-interactive
102
+ debug1: Authentications that can continue: publickey,password,keyboard-interactive
103
+ debug1: Next authentication method: password

1

修正箇所の追記

2018/03/16 04:53

投稿

minhouse10
minhouse10

スコア41

title CHANGED
File without changes
body CHANGED
@@ -33,4 +33,21 @@
33
33
  interact
34
34
  "
35
35
  done < ${ip_file
36
+ ```
37
+
38
+ 修正箇所
39
+ ```ここに言語を入力
40
+ コードを以下の様に変更した結果、パスワードプロンプトで停止せずスクリプトの実行は終了たが、scpの処理が実行されない。
41
+
42
+ expect {
43
+ \" Are you sure you want to continue connecting (yes/no)? \" {
44
+ send \"yes\r\"
45
+ expect \"${USER}@${line}'s password:\"
46
+ -re \"${USER}@${line}'s password:\"
47
+ send \"${PASS}\r\"
48
+ } -re \"${USER}@${line}'s password:\" {
49
+ send \"${PASS}\r\"
50
+ }
51
+ interact
52
+ "
36
53
  ```