Created
April 29, 2013 13:59
-
-
Save mlebkowski/5481726 to your computer and use it in GitHub Desktop.
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 | |
LIST=`su -c "screen -ls" $SUDO_USER | grep -Eo '[0-9]\S+\s'` | |
# LIST="31702.test" | |
for SOCKET in $LIST; do | |
PID=`echo $SOCKET|cut -d. -f 1` | |
NAME=`echo $SOCKET|cut -d. -f 2` | |
DIR=`pwdx $PID | cut -d" " -f 2` | |
echo "Screen $NAME running at $PID from $DIR" | |
( | |
echo "source $(getent passwd $SUDO_USER | cut -d: -f 6 )/.screenrc" | |
echo | |
echo "sessionname '$NAME'" | |
echo | |
i=0; | |
pgrep -P $PID | while read PID | |
do | |
cmd=`ps h -o pid,cmd --ppid "$PID"` | |
[ $? -eq 0 ] || continue; | |
PID=`echo $cmd | cut -d' ' -f 1` | |
CMD=`echo $cmd | sed "s/$PID //"` | |
DIR=`pwdx $PID | cut -d' ' -f 2` | |
echo "chdir '$DIR'" | |
echo "screen $i" | |
echo "stuff '$CMD'" | |
echo | |
i=$((i+1)) | |
done | |
echo "chdir '$DIR'" | |
echo | |
) > "${NAME}.screen" | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment