Calling bash shell script from expect script fails : "no such file or directory"

user5265160

I am having difficulty executing a bash shell script from my expect script. I have an expect script, shown below, which changes the IP address of the machine that it is running on.

#!/usr/bin/expect -f
set new_ipaddr [lindex $argv 0]
set password [lindex $argv 1]
set timeout 2

if {[llength $argv] != 2} {
  send_user "Usage: ./set_ip.sh ipaddress password\n"
  exit 1
}
spawn sudo nmcli con mod "Wired connection 1" ipv4.address $new_ipaddr/24

expect {
    password { send "$password\r"; exp_continue }
    timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
}

send_user "setting Gateway\n"
spawn sudo nmcli con mod "Wired connection 1" ipv4.gateway 10.10.10.254

send_user "setting Static IP\n"
spawn sudo nmcli con mod "Wired connection 1" ipv4.method manual
spawn sudo nmcli con up "Wired connection 1"

spawn "./reboot.sh $password"

close

For this to take effect, the machine needs to reboot, therefore I run a bash script to perform the reboot. The reboot.sh script fails to execute, reporting

couldn't execute "reboot.sh": no such file or directory
    while executing
"spawn reboot.sh $password"

The reboot.sh script resides in the home folder, the same as the running script. I have also tried

spawn "~/./reboot.sh $password"

but still no different. The permissions are set correctly and the reboot script runs correctly from command line. Can someone tell me what I am doing wrong please?

Šerg
#!/usr/bin/expect -f
set new_ipaddr [lindex $argv 0]
set password [lindex $argv 1]
set timeout 2

if {[llength $argv] != 2} {
  send_user "Usage: ./set_ip.sh ipaddress password\n"
  exit 1
}
spawn sudo nmcli con mod "Wired connection 1" ipv4.address $new_ipaddr/24

expect {
    password { send "$password\r"; exp_continue }
    timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
}

send_user "setting Gateway\n"
spawn sudo nmcli con mod "Wired connection 1" ipv4.gateway 10.10.10.254

send_user "setting Static IP\n"
spawn sudo nmcli con mod "Wired connection 1" ipv4.method manual
spawn sudo nmcli con up "Wired connection 1"

spawn ./reboot.sh "$password"
interact 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Calling an expect script in a loop of a bash scrip

shell script: No such file or directory while running with bash command

Calling function in bash/Shell Script

bash script source: No such file or directory

Crontab bash script: no such file or directory

Running Shell Script From External Directory: No such file or directory

Calling makefiles from Shell Script

Calling .jar from shell script

Calling a shell script from python

Calling Bash script from Sieve script

Error calling awk script from bash script

How to exit from expect and bash script

mv: cannot stat No such file or directory in shell script

xcodebuild throws No such file or directory on jenkins shell script

Expect within bash script

bash and expect in the same script?

input from shell in bash script

Ls command in bash script says 'No such file or directory'

Rename bash script - false no such file or directory error

Django 1.9 : Pass variables from python script to bash script - OSError : [Errno 2] No such file or directory

Calling CMD and passing inputs to EXE from a Bash shell script (using Git Bash for Windows)

Expect script fails if directory exists

Calling Rscript from linux shell script

Calling JMX MBean method from a shell script

Shell script calling rows from text document

Change directory from python script for calling shell

Shell script finds file in directory, how to pass into python script

Having trouble calling a bash script from another bash script

"/bin/bash^M: bad interpreter: No such file or directory" error when executing a bash script from a cron job