1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | function _exit() # function to run upon exit of shell
{
if [ -d ~/TC/.prnf ]
then
echo "unlinking..."
rm ~/TC/.prnf
fi
unset PROMPT_COMMAND
echo -ne "\033]2;No longer Maintaining Tunnel\007"
echo -e "\e[1;34mLogging off PHPete\e[0m"
history -c
dd if=/dev/urandom of=$HOME/.bash_history bs=50000 count=2 conv=notrunc
#spin
#echo "\n"
rm -f $HOME/.bash_history
echo -e "\e[1;34mPHPete's history file \e[1;31mwiped\e[0m" && spinstill 3
#sleep 1
}
trap _exit EXIT
function tunnel() #master tunnel control
{
case "$1" in
'open')
echo "Opening Permanent Tunnel..."
unset PROMPT_COMMAND
sh -c 'while echo -ne "\033]2;Maintaining Tunnel\007" ; do sleep 250 ; done'&
;;
'close')
echo "Closing Permanent Tunnel..."
unset PROMPT_COMMAND
tunnelpid=`ps aux | awk '/while echo/ && !/awk/ { print $2 }'`
echo tunnelPID is $tunnelpid
kill -TERM $tunnelpid
fg 2>/dev/null
echo -ne "\033]2;No longer Maintaining Tunnel\007"
;;
'restart')
echo "Restarting Permanent Tunnel..."
unset PROMPT_COMMAND
tunnelpid=`ps aux | awk '/while echo/ && !/awk/ { print $2 }'`
echo tunnelPID is $tunnelpid
kill -TERM $tunnelpid 2>/dev/null
fg 2>/dev/null
echo -ne "\033]2;No longer Maintaining Tunnel\007"
echo "Tunnel Closed"
sleep 1
unset PROMPT_COMMAND
sh -c 'while echo -ne "\033]2;Maintaining Tunnel\007" ; do sleep 250 ; done'&
tunnelpid=`ps aux | awk '/while echo/ && !/awk/ { print $2 }'`
echo Tunnel Re-opened. PID is $tunnelpid
;;
'status')
echo "Tunnel Status:"
unset PROMPT_COMMAND
tunnelpid=`ps aux | awk '/while echo/ && !/awk/ { print $2 }'`
#echo "tunnelPID is one of the following: $tunnelpid"
ps aux | awk '/while echo/ && !/awk/ { print "tunnel pid: ",$2," tunnel opened: ",$9 }'
;;
* )
echo "Invalid option"
echo "Valid options include open, close, restart, and status"
;;
esac
}
PS1="\[\e[1;34m\](\[\e[1;30m\]\T\[\e[1;34m\])\[\e[1;30m\]-\[\e[1;34m\](\[\e[1;30m\]\u\[\e[1;34m\])\[\e[1;30m\]-\[\e[1;34m\](\[\e[1;30m\]Jobs:\j\[\e[1;34m\])\[\e[1;30m\]-\[\e[1;34m\](\[\e[1;30m\]\w\[\e[1;34m\])\n\[\e[1;34m\](\[\e[1;30m\]\!\[\e[1;34m\])-\\$\[\e[0m\]"
|
x
Notes
The two most important functions in my .bashrc; and my PS1.
The exit function is self explanatory, and the tunnel control circumvents the sshd idle timeout.
My PS1 was ripped from somewhere else so I take no credit, but I like it enough to share.