Linux&&shell&&/usr/bin/expect: bad interpreter: No such file or directory
问题现象:
root@dfq:/home# nohup ./scp.sh &
[1] 1787
root@dfq:/home# nohup: ignoring input and appending output to ‘nohup.out’
nohup: failed to run command ‘./scp.sh’: No such file or directory
^C
[1]+ Exit 127 nohup ./scp.sh
root@dfq:/home# ./scp.sh
-bash: ./scp.sh: /usr/bin/expect: bad interpreter: No such file or directory
问题分析:
先贴个脚本
#!/usr/bin/expect -f
#定义密码
set password qwe123
#download
spawn scp -r -P 27 root@192.168.1.11:/mnt/backup/192.168.1.11.tar.gz /home/
set timeout 300
expect "root@192.168.1.11's password:"
set timeout 300
send "$password\r"
set timeout 300
send "exit\r"
expect eof
脚本中第一行调用了"#!/usr/bin/expect -f",该服务不存在,所以提示文件不存在错误。
解决方法:
root@dfq:/home# apt-get install expect
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libtcl8.6
Suggested packages:
tcl8.6
The following NEW packages will be installed:
expect libtcl8.6
0 upgraded, 2 newly installed, 0 to remove and 60 not upgraded.
Need to get 992 kB of archives.
After this operation, 4,115 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main libtcl8.6 amd64 8.6.1-4ubuntu1 [841 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty/main expect amd64 5.45-5ubuntu1 [152 kB]
Fetched 992 kB in 2s (441 kB/s)
Selecting previously unselected package libtcl8.6:amd64.
(Reading database ... 85279 files and directories currently installed.)
Preparing to unpack .../libtcl8.6_8.6.1-4ubuntu1_amd64.deb ...
Unpacking libtcl8.6:amd64 (8.6.1-4ubuntu1) ...
Selecting previously unselected package expect.
Preparing to unpack .../expect_5.45-5ubuntu1_amd64.deb ...
Unpacking expect (5.45-5ubuntu1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up libtcl8.6:amd64 (8.6.1-4ubuntu1) ...
Setting up expect (5.45-5ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.14) ...
root@dfq:/home# nohup ./scp.sh &
[1] 2137
root@dfq:/home# nohup: ignoring input and appending output to ‘nohup.out’