-
Notifications
You must be signed in to change notification settings - Fork 1
/
sshm-update
executable file
·38 lines (31 loc) · 877 Bytes
/
sshm-update
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
#!/bin/bash
set -o errexit
DATA_PATH="$HOME/.sshm"
DATA_FILE="$HOME/.sshm/.data"
function update_data_file()
{
now=$(date +%s)
count=$(sed -rn "/^[[:digit:]]+ [[:digit:]]+ $1$/p" $DATA_FILE | awk '{print $2}')
if [[ -z $count ]]; then
echo "This is the first time you login to $1" >> /tmp/sshm.log
echo "$now 1 $1" >> $DATA_FILE
else
count=$(expr $count + 1)
echo "This is the $count time you login to $1" >> /tmp/sshm.log
sed -ri "s/^[[:digit:]]+ [[:digit:]]+ $1$/$now $count $1/g" $DATA_FILE
fi
sort -nr $DATA_FILE -o $DATA_FILE
}
if [[ ! -d "$DATA_PATH" ]]; then
echo "$DATA_PATH doesn't exist."
mkdir -p $DATA_PATH
fi
if [[ ! -e $DATA_FILE ]]; then
echo "$DATA_FILE doesn't exist"
touch $DATA_FILE
fi
if [[ -n $1 ]]; then
update_data_file "$*"
else
echo "You need transfer an argument to this script." >> /tmp/sshm.log
fi