linux - 如何执行shell脚本?

标签 linux bash shell sh

如何执行shell scipt?

当我运行脚本时使用:

jalaj@jalaj-SVF14212SNB sudo ./startvpn.sh  
[sudo] password for jalaj: 
sudo: unable to execute ./startvpn.sh: Permission denied //It says

当我使用 sudo sh startvpn.sh [sudo] jalaj 的密码:

I get the output as 

startvpn.sh: 2: startvpn.sh: spawn: not found
startvpn.sh: 3: startvpn.sh: expect: not found
startvpn.sh: 4: startvpn.sh: expect: not found
startvpn.sh: 5: startvpn.sh: interact: not found

下面是我的脚本

#!/usr/bin/expect 
spawn openconnect --no-cert-check 103.194.44.2
expect -exact "Username:"send -- "XYX\n"
expect -exact "Password:"send -- "XYX%"
interact

我使用

检查了上述权限
-rwxrw---x 1 jalaj jalaj 168 Aug 10 12:29 startvpn.sh

它说用户 jalaj 可以执行,但我不能执行。
谁能指导我如何执行脚本?

最佳答案

您必须确保实际安装了 expect:

类 Debian:

sudo apt-get install expect

类似于 RedHat:

sudo yum install expect

然后你可能想使用 sudo 来执行你的脚本。


同时检查之前提出的这个问题:"Use expect in bash script to provide password to SSH command"

关于linux - 如何执行shell脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45627326/

相关文章:

linux - Linux 4.0 上的 Intel Pin 工具

bash - 如何在脚本中使用 exec 3>myfifo,而不是让 echo foo>&3 关闭管道?

bash - 修改.bashrc失败

linux - 标准 |用包含双引号的环境变量替换值

regex - sed 删除括号后的尾随空格

shell - Visual Studio 2010 Shell 隔离模板损坏

linux - 在 shell 脚本中获取命令输出

linux - 如何自动获得IP地址更改通知

c - 我需要在没有节标题的共享对象上链接 C 程序

php - IPMItool 设置用户角色