Created
October 28, 2018 04:05
-
-
Save highgain86j/bdfce02e2ed802ca041dc40c76218fc4 to your computer and use it in GitHub Desktop.
screen for backgrounding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function launch(){ | |
local execbin="`which ${target}`" | |
local str="`screen -list "${target}" | egrep 'Detached|Attached' | awk '{print $1}'`" | |
ps aux | egrep -v 'grep|ps aux|screen|SCREEN' | grep pts | grep \^${USER} | grep ${target} | |
if [ "${str}" != "" ]; then | |
echo -e "\"${str}\" is present." | |
echo "Reattaching... (ignoring options)" | |
sleep 1 | |
str="`screen -list | grep "${target}" | grep "Attached" | awk '{print $1}'`" | |
if [ "${str}" == "" ]; then | |
screen -r ${str} | |
else | |
screen -rx ${str} | |
fi | |
else | |
screen -dmS ${target} ${execbin} "${@}" | |
echo -e "Created \"`screen -list | grep "${target}" | awk '{print $1}'`\", running ${target} with PID:`pidof ${target}`." | |
fi | |
} | |
args0=("${@}") | |
args1=(`for ((c=1; c<${#args0[@]}; c++)); do echo "${args0[${c}]}"; done`) | |
target=${args0[0]} | |
launch "${args1[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment