Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: timeout problem in ssh sessions
- X-seq: zsh-users 12582
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: ZSH User List <zsh-users@xxxxxxxxxx>
- Subject: Re: timeout problem in ssh sessions
- Date: Fri, 15 Feb 2008 12:30:47 -0800
- In-reply-to: <20080215103220.GF31852@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20080211233404.GA13398@xxxxxxxxx> <080212083755.ZM20121@xxxxxxxxxxxxxxxxxxxxxx> <20080212232947.GA13793@xxxxxxxxx> <080212200708.ZM20711@xxxxxxxxxxxxxxxxxxxxxx> <20080213134200.GB31852@xxxxxxxxx> <200802131349.m1DDnXRF004831@xxxxxxxxxxxxxx> <27b8b8a0802130621x47568c7fo304848d02a1c6e76@xxxxxxxxxxxxxx> <20080213143803.GI619@xxxxxxxxxxxxxxxxxxx> <20080214125415.GC31852@xxxxxxxxx> <20080214180818.GO619@xxxxxxxxxxxxxxxxxxx> <20080215103220.GF31852@xxxxxxxxx>
On Feb 15, 11:32am, Andy Spiegl wrote:
} Subject: Re: timeout problem in ssh sessions
}
} Thanks to Vincent and Stephane I came up with the following .zlogout
Some suggestions follow.
} ---------------------.-----------------.------------.-----------------
} echo "Terminating shell (PID $$) on TTY `tty|cut -dy -f2`:"
No need for tty|cut:
echo "Terminating shell (PID $$) on TTY ${TTY#*y}:"
} 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"
Why do you need ignore-case in that grep? Surely you want to match "USER"
case-sensitively? However, you probably DO want to match the PID as a word
by itself, otherwise e.g. "8654" would match "28654".
/bin/grep -wE "(^USER|$$)" =(ps -eo user,pid,ppid,s,cpu,pmem,rss,vsize,bsdstart,etime,bsdtime,cmd)
Better still, since you're about to do the same ps|grep on the PPID:
ps="$(ps -eo user,pid,ppid,s,cpu,pmem,rss,vsize,bsdstart,etime,bsdtime,cmd)"
echo "Terminating shell (PID $$) on TTY ${TTY#*y}:"
/bin/grep -wE "(^USER|$$)" <<<$ps
echo ""
echo Parent process (PPID $PPID):
/bin/grep -wE "(^USER|$PPID)" <<<$ps
echo ""
For the die-hards in the crowd, yes, the grep could be replaced with:
print -l ${(M)${(f)ps}:#(USER*|* $$ *)}
} echo -n "Still open file descriptors: "
} perl -e 'print join(" ", grep { -t $_ } 0..63)."\n"'
} echo ""
That's only telling you which descriptors are still connected to the tty,
not which ones are open, so you'll miss X connections and the like.
If that's really what you want, though, you don't need perl:
echo -n "Still open file descriptors: "
for fd in {0..63}; [[ -t $fd ]] && echo -n "$fd "; echo ""
echo ""
} if whence xsel > /dev/null 2>&1; then
No need for this test: If it's not in the ps output, you're not going
to do anything with it, and if it is in the ps output, it must exist,
right?
} 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 you take my suggestion above, you've already got $ps:
LEFTOVER="$( /bin/grep -wE xsel <<<$ps )"
} 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!'
} ---------------------.-----------------.------------.-----------------
Messages sorted by:
Reverse Date,
Date,
Thread,
Author