Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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";
share|improve this question
up vote 0 down vote accepted

I ended up using the -k flag of sudo to invalidate the time stamp. so i just added that flag to every sudo call and let expect pass in the password.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .