Skip to content

Instantly share code, notes, and snippets.

View mkramlich's full-sized avatar

Mike Kramlich mkramlich

  • Denver, CO, USA
View GitHub Profile
@cowboy
cowboy / sudo-keepalive-example.sh
Created July 15, 2012 20:55
Bash: Sudo keep-alive (good for long-running scripts that need sudo internally but shouldn't be run with sudo)
#!/bin/bash
# Might as well ask for password up-front, right?
sudo -v
# Keep-alive: update existing sudo time stamp if set, otherwise do nothing.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Example: do stuff over the next 30+ mins that requires sudo here or there.
function wait() {