Skip to content

Instantly share code, notes, and snippets.

@mlebkowski
Created April 29, 2013 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlebkowski/5481726 to your computer and use it in GitHub Desktop.
Save mlebkowski/5481726 to your computer and use it in GitHub Desktop.
#!/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