Skip to content

Instantly share code, notes, and snippets.

@mattbell87
Created February 24, 2016 23:59
Show Gist options
  • Save mattbell87/eac373d9f26a22e01605 to your computer and use it in GitHub Desktop.
Save mattbell87/eac373d9f26a22e01605 to your computer and use it in GitHub Desktop.
Keep sudo alive until a bash script has finished.
#!/bin/bash
# Ask for password
sudo -v
# Or give the password if you know it
# echo 'PASSWORD' | sudo -vS
while true; do sudo -n true; sleep 60; kill -0 \"$$\" || exit; done 2>/dev/null &
# do stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment