how I can provide my password repeatedly to the script?
and ewatt's answer shows a direct way of doing that.
Using the "NOPASSWD" flag for the "sudo mycmd" rule would avoid asking for your password at all, as ewatt mentioned.
Alternatively, if you don't want to hard-code your password in a script, tell sudo that it's OK to cache the password for this particular command until the next reboot by setting the timestamp_timout to a negative value. Here, I've defined an alias for the command (arbitrarily replaced as /tmp/mycmd.sh) and used that in the
Cmnd_Alias MYCMD = /tmp/mycmd.sh
tim ALL = MYCMD
Alternatively, you could set a user-level timeout default:
... which would mean that your timestamp for any sudo command would be cached until the next reboot.
Or, alternatively still, timeouts for any command and any user, but on a particular host:
Setting the timestamp_timeout this way allows sudo to cache your password after the first time you enter it.
If you implement one of the
Defaults options in order to avoid entering your password during each loop of the script, but prefer the safety net of entering your password for separate activities, then run
sudo -k to tell sudo to "kill" (or reset) your timestamp, so that you'll be prompted for it next time. Note that you'll restart this "cached" ... "reset" process each time you authenticate to sudo.
If "until the next reboot" is too long for you, then set it to a value that's larger "enough" than 10000 seconds -- in minutes, so more than 166! -- to allow you to notice and enter the password for each loop.