How to NOT have to enter sudo password multiple times!
Found a cool way to do a script (by Sparhawk in StackExchange) so that if you use sudo more than once or if a command requires you to enter your password, you should only have to enter it once.
I've used it already in my TCServer_restart.sh script and it works great!
sudo_done="/tmp/sudo.finished"
sudo_me() {
while [ ! -f $sudo_done ]; do
sudo -v
sleep 5
done &
}
stop_sudoing() {
touch $sudo_done
sleep 7
rm $sudo_done
}
sudo_me &
#### Your script here.
stop_sudoing &
Just replace/add your stuff at the "# Your script here." and away you go!
There might be a way to have this in a separate bash script and then just include it into your script. It seems that the sudo_me &
and the stop_sudoing &
are what you would need to have explicitly in your script (after including the other, obviously).
If I use this more, I'll probably do something like that.