Skip to content

Instantly share code, notes, and snippets.

@Ruxton
Created July 18, 2011 02:32
Show Gist options
  • Save Ruxton/1088435 to your computer and use it in GitHub Desktop.
Save Ruxton/1088435 to your computer and use it in GitHub Desktop.
# __screend: screen daemonizing
__screend() {
local name="${1}"
local check=`screen -list|grep $name|awk '{print $1}'`
if [[ "$2" = "" ]]; then
if [[ "${check}" = "" ]]; then
screen -dmS $name $name > /dev/null
local runCheck=`screen -list|grep $name|awk '{print $1}'`
if [[ "${runCheck}" = "" ]]; then
echo "Unable to start ${name} in background"
else
echo "Started ${name} in background"
fi
else
echo "${name} is running in background..."
read -ep "re-attach? (y/n)" choice
if [[ $choice = [yY] ]]; then
echo "Attaching ${name} session..."
screen -r $check
else
echo "${name} currently running at ${check}"
fi
fi
else
if [[ $2 -eq "load" ]]; then
screen -r $name
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment