Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: timeout problem in ssh sessions



Thanks to Vincent and Stephane I came up with the following .zlogout now
which solves all my problems _and_ is interesting to read:

---------------------.-----------------.------------.-----------------
echo "Terminating shell (PID $$) on TTY `tty|cut -dy -f2`:"
ps -eo user,pid,ppid,s,cpu,pmem,rss,vsize,bsdstart,etime,bsdtime,cmd | /bin/grep -v "etime,bsdtime,cmd" | /bin/grep -iE "(^USER|$$)" | /bin/grep -v "grep -iE"
echo ""

echo Parent process (PPID $PPID):
ps -eo user,pid,ppid,s,cpu,pmem,rss,vsize,bsdstart,etime,bsdtime,cmd | /bin/grep -v "etime,bsdtime,cmd" | /bin/grep -iE "(^USER|$PPID)" | /bin/grep -v "grep -iE"
echo ""

echo -n "Still open file descriptors: "
perl -e 'print join(" ", grep { -t $_ } 0..63)."\n"'
echo ""

if whence xsel > /dev/null 2>&1; then
  LEFTOVER=`ps -eo user,pid,ppid,s,cpu,pmem,rss,vsize,bsdstart,etime,bsdtime,cmd | /bin/grep -v "etime,bsdtime,cmd" | /bin/grep -iE xsel | /bin/grep -v "grep -iE"`
  if [[ -n $LEFTOVER ]]; then
    echo 'Leftover "xsel" process:'
    echo $LEFTOVER

    # kill xsel (started by .zsh/functions/mouse.support) if in a ssh session
    # otherwise sshd will hang until the X clipboard is read or cleared
    if [[ -z ${OSTYPE:#linux*} && -n $SSH_CLIENT &&
       ${(M)${(f)"$(</proc/$PPID/status)"}:#Name:*} == Name:[[:blank:]]sshd ]]; then
      echo -n "Terminating xsel..."
      xsel -c -b
      echo -e "done.\n"

      # or kill the parent sshd (pretty brutal, might close other programs!)
      # kill -HUP $PPID 2>/dev/null
    fi
  fi
fi

echo 'Last user was: '`whoami`'.  Bye!'
---------------------.-----------------.------------.-----------------

Thanks guys!
 Andy.

-- 
 As far as we know our computer has never had an undetected error.



Messages sorted by: Reverse Date, Date, Thread, Author