曾遇到這樣一段代碼:(Bash腳本)php
1
2
3
4
5
6
7
8
9
10
11
12
|
#!/usr/bin/expect -f
set HOST
"192.168.102.1"
set USER
"codefor"
set PASS
"codefor"
set BOOKFILE
"/home/codefor"
#upload
spawn
"scp *.zip $USER@$HOST:$BOOKFILE"
expect {
"*password*"
{send
"$PASS\r"
;}
}
expect eof;
|
這樣的話,會報不存在*.zip的錯誤,即不能解析通配符*bash
在命令前加上bash -c便可。spa
以下:code
1
2
3
4
5
6
7
8
9
10
11
12
|
#!/usr/bin/expect -f
set HOST
"192.168.102.1"
set USER
"codefor"
set PASS
"codefor"
set BOOKFILE
"/home/codefor"
#upload
spawn bash -c
"scp *.zip $USER@$HOST:$BOOKFILE"
expect {
"*password*"
{send
"$PASS\r"
;}
}
expect eof;
|