I have a main shell script that prompts the user for his password. I then would like to call an expect script while passing the password to it. This expect script will run 3 sudo commands.
I know the linux boxes my script is going to get run on have timestamp_timeout set to some value in their sudoers. My problem is that i have a general idea of how to write this expect but don't know how to handle the following cases :
1) I can send the password to the first sudo command fine. This sudo will delete a large directory that may take several minutes to delete which may or may not be greater than the timestamp_timeout value set. So how can i make expecting a password prompt for my second and third sudo commands optional.
2) Say for some strange reason script dies or the user aborts it. When he tries to run it again we are still within the time of timestamp_timeout. This requires the expect password for the first command be optional too.
Here is what i have so far:
#!/usr/bin/expect
set password [lindex $argv 0]
spawn sudo rm -rvf /mnt/repo
expect "*?assword:*"
send "$password\r"
send "sudo mkdir -v /mnt/hwrrepo"
expect "*?assword:*"
send "$password\r";
send "sudo chmod -R 777 /mnt/hwrrepo"
expect "*?assword:*"
send "$password\r";
interact