Expect and sudo timeout

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 


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.

Category: linux Time: 2013-03-01 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.291 (s). 12 q(s)