Jalaj Chawla
Jalaj Chawla

Reputation: 189

How to execute shell script?

How to execute the shell scipt?

When I ran my script using:

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

When I execute this using sudo sh startvpn.sh [sudo] password for 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

Below is my script

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

I checked the above permission using

-rwxrw---x 1 jalaj jalaj 168 Aug 10 12:29 startvpn.sh

It say users jalaj can execute but I am not able to execute.
Can anyone guide me how to execute the script?

Upvotes: 1

Views: 197

Answers (1)

Ayman Nedjmeddine
Ayman Nedjmeddine

Reputation: 12759

You have to ensure expect is actually installed:

Debian-like:

sudo apt-get install expect

RedHat-like:

sudo yum install expect

Then you might want to use sudo to execute your script.


Check this previously asked question as well: "Use expect in bash script to provide password to SSH command"

Upvotes: 1

Related Questions