質問編集履歴

6

修正

2021/11/24 11:16

投稿

minhouse10
minhouse10

スコア41

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  USER='ohm'
28
28
 
29
- PASS='#!8102L#>t'
29
+ PASS='#xxxxxxxx'
30
30
 
31
31
  TARGET_DIR='test.txt'
32
32
 

5

成功ログ

2021/11/24 11:16

投稿

minhouse10
minhouse10

スコア41

test CHANGED
File without changes
test CHANGED
@@ -267,3 +267,55 @@
267
267
  }"
268
268
 
269
269
  [root@host]
270
+
271
+
272
+
273
+ ---------------
274
+
275
+ 修正版:成功!!
276
+
277
+
278
+
279
+ expect -c "
280
+
281
+ set timeout 5
282
+
283
+ spawn scp -v ${TARGET_DIR} ${USER}@${line}:${CR_DIR}
284
+
285
+ expect \"${USER}@${line}'s password:\" {
286
+
287
+ send \"${PASS}\n\"
288
+
289
+ }
290
+
291
+ expect \"${USER}@${line}'s password:\" {
292
+
293
+ send \"${PASS}\n\"
294
+
295
+ }
296
+
297
+ "
298
+
299
+
300
+
301
+ 結果:
302
+
303
+ Sending file modes: C0755 0 test.txt
304
+
305
+ Sink: C0755 0 test.txt
306
+
307
+ test.txt 100% 0 0.0KB/s 00:00
308
+
309
+ debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
310
+
311
+ debug1: channel 0: free: client-session, nchannels 1
312
+
313
+ debug1: fd 0 clearing O_NONBLOCK
314
+
315
+ debug1: fd 1 clearing O_NONBLOCK
316
+
317
+ Transferred: sent 2688, received 4328 bytes, in 0.1 seconds
318
+
319
+ Bytes per second: sent 25747.9, received 41457.1
320
+
321
+ debug1: Exit status 0

4

追記

2018/03/16 06:34

投稿

minhouse10
minhouse10

スコア41

test CHANGED
File without changes
test CHANGED
@@ -207,3 +207,63 @@
207
207
 
208
208
 
209
209
  ohm@22.222.22.222's password: [root@host]#
210
+
211
+
212
+
213
+ -----------
214
+
215
+ 修正後:
216
+
217
+ while read line || [ -n "${line}" ];
218
+
219
+ do
220
+
221
+ expect -c "
222
+
223
+ set timeout 5
224
+
225
+ spawn scp -v ${TARGET_DIR} ${USER}@${line}:${CR_DIR}
226
+
227
+ expect {
228
+
229
+ \"${USER}@${line}'s password:\"
230
+
231
+ send \"${PASS}\n\"
232
+
233
+ }
234
+
235
+ -re \"[Pp]assword:\" {
236
+
237
+ send \"${PASS}\n\"
238
+
239
+ }
240
+
241
+ interact
242
+
243
+ "
244
+
245
+ done < ${ip_file}
246
+
247
+
248
+
249
+ 結果:
250
+
251
+ debug1: Next authentication method: password
252
+
253
+ ohm@22.222.22.222's password: usage: send [args] string
254
+
255
+ while executing
256
+
257
+ "send"
258
+
259
+ invoked from within
260
+
261
+ "expect {
262
+
263
+ "ohm@22.222.22.222's password:"
264
+
265
+ send "#!8102L#>t\n"
266
+
267
+ }"
268
+
269
+ [root@host]

3

ログ追記

2018/03/16 06:21

投稿

minhouse10
minhouse10

スコア41

test CHANGED
File without changes
test CHANGED
@@ -203,3 +203,7 @@
203
203
  debug1: Authentications that can continue: publickey,password,keyboard-interactive
204
204
 
205
205
  debug1: Next authentication method: password
206
+
207
+
208
+
209
+ ohm@22.222.22.222's password: [root@host]#

2

ログの追加

2018/03/16 05:10

投稿

minhouse10
minhouse10

スコア41

test CHANGED
File without changes
test CHANGED
@@ -103,3 +103,103 @@
103
103
  "
104
104
 
105
105
  ```
106
+
107
+ scp -vオプションを付けて実行した結果になります。scpコマンドは実行されている事が確認。
108
+
109
+ [root@host]# bash scp_auto.sh
110
+
111
+ spawn scp -v test.txt ohm@22.222.22.222:/tmp
112
+
113
+ Executing: program /usr/bin/ssh host 22.222.22.222, user far, command scp -v -t /tmp
114
+
115
+ OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
116
+
117
+ debug1: Reading configuration data /etc/ssh/ssh_config
118
+
119
+ debug1: /etc/ssh/ssh_config line 56: Applying options for *
120
+
121
+ debug1: Connecting to 22.222.22.222 [22.222.22.222] port 22.
122
+
123
+ debug1: Connection established.
124
+
125
+ debug1: permanently_set_uid: 0/0
126
+
127
+ debug1: identity file /root/.ssh/id_rsa type -1
128
+
129
+ debug1: identity file /root/.ssh/id_rsa-cert type -1
130
+
131
+ debug1: identity file /root/.ssh/id_dsa type -1
132
+
133
+ debug1: identity file /root/.ssh/id_dsa-cert type -1
134
+
135
+ debug1: identity file /root/.ssh/id_ecdsa type -1
136
+
137
+ debug1: identity file /root/.ssh/id_ecdsa-cert type -1
138
+
139
+ debug1: identity file /root/.ssh/id_ed25519 type -1
140
+
141
+ debug1: identity file /root/.ssh/id_ed25519-cert type -1
142
+
143
+ debug1: Enabling compatibility mode for protocol 2.0
144
+
145
+ debug1: Local version string SSH-2.0-OpenSSH_6.6.1
146
+
147
+ debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2
148
+
149
+ debug1: match: OpenSSH_7.2 pat OpenSSH* compat 0x04000000
150
+
151
+ debug1: SSH2_MSG_KEXINIT sent
152
+
153
+ debug1: SSH2_MSG_KEXINIT received
154
+
155
+ debug1: kex: server->client aes128-ctr hmac-sha1 none
156
+
157
+ debug1: kex: client->server aes128-ctr hmac-sha1 none
158
+
159
+ debug1: kex: curve25519-sha256@libssh.org need=20 dh_need=20
160
+
161
+ debug1: kex: curve25519-sha256@libssh.org need=20 dh_need=20
162
+
163
+ debug1: sending SSH2_MSG_KEX_ECDH_INIT
164
+
165
+ debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
166
+
167
+ debug1: Server host key: RSA c2:ae:1e:70:c4:82:7e:21:49:36:5d:4a:29:6a:2d:a9
168
+
169
+ debug1: Host '22.222.22.222' is known and matches the RSA host key.
170
+
171
+ debug1: Found key in /root/.ssh/known_hosts:18
172
+
173
+ debug1: ssh_rsa_verify: signature correct
174
+
175
+ debug1: SSH2_MSG_NEWKEYS sent
176
+
177
+ debug1: expecting SSH2_MSG_NEWKEYS
178
+
179
+ debug1: SSH2_MSG_NEWKEYS received
180
+
181
+ debug1: Roaming not allowed by server
182
+
183
+ debug1: SSH2_MSG_SERVICE_REQUEST sent
184
+
185
+ debug1: SSH2_MSG_SERVICE_ACCEPT received
186
+
187
+
188
+
189
+ debug1: Authentications that can continue: publickey,password,keyboard-interactive
190
+
191
+ debug1: Next authentication method: publickey
192
+
193
+ debug1: Trying private key: /root/.ssh/id_rsa
194
+
195
+ debug1: Trying private key: /root/.ssh/id_dsa
196
+
197
+ debug1: Trying private key: /root/.ssh/id_ecdsa
198
+
199
+ debug1: Trying private key: /root/.ssh/id_ed25519
200
+
201
+ debug1: Next authentication method: keyboard-interactive
202
+
203
+ debug1: Authentications that can continue: publickey,password,keyboard-interactive
204
+
205
+ debug1: Next authentication method: password

1

修正箇所の追記

2018/03/16 04:53

投稿

minhouse10
minhouse10

スコア41

test CHANGED
File without changes
test CHANGED
@@ -69,3 +69,37 @@
69
69
  done < ${ip_file
70
70
 
71
71
  ```
72
+
73
+
74
+
75
+ 修正箇所
76
+
77
+ ```ここに言語を入力
78
+
79
+ コードを以下の様に変更した結果、パスワードプロンプトで停止せずスクリプトの実行は終了たが、scpの処理が実行されない。
80
+
81
+
82
+
83
+ expect {
84
+
85
+ \" Are you sure you want to continue connecting (yes/no)? \" {
86
+
87
+ send \"yes\r\"
88
+
89
+ expect \"${USER}@${line}'s password:\"
90
+
91
+ -re \"${USER}@${line}'s password:\"
92
+
93
+ send \"${PASS}\r\"
94
+
95
+ } -re \"${USER}@${line}'s password:\" {
96
+
97
+ send \"${PASS}\r\"
98
+
99
+ }
100
+
101
+ interact
102
+
103
+ "
104
+
105
+ ```