-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsshh
executable file
·48 lines (40 loc) · 1.64 KB
/
sshh
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
#!/bin/sh
# SSH History Logger 1.0.6
# Copyright (C) Alexander Kozhevnikov <[email protected]> 2015-06-05;
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public Licence as published by
# the Free Software Foundation, either version 3 of the licence or,
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for details.
#
# You should've received a copy of the GNU General Public License
# with this program. If not, see <http://www.gnu.org/licences/>,
# or write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330 Boston MA 02111-1307 USA.
# On 2015-06-05, this script was compatible with Bourne and POSIX shells.
logdir=~/.ssh_history
case $ZSH_VERSION in ?*) alias -g '${1+"$@"}="$@"'; esac
# Create the folder with user-only read+search permissions if it doesn't exist.
mkdir -m 700 -p "$logdir" || exit 1
# ISO8601 allows for time to be specified with or without colons. But MSDOS and
# Windows ruined it for everyone (to this day exFAT, a common filesystem on USB
# drives, SD cards, etc, does not support colons in filenames), so support for
# colons in filenames is limited in the wild. Therefore, going with the
# no-colon option.
timestamp=`date -Is | sed s/://g`
logfile=`mktemp "$logdir"/"$timestamp"_"$*"_XXXXXX` || exit 2
exec 4>&1
exitcode=`
{
{
ssh ${1+"$@"} 3>&-
printf $? 1>&3
} 4>&- | tee -i "$logfile" 1>&4
} 3>&1`
exec 4>&-
exit $exitcode