Repository navigation
Expand file tree
/
Copy pathfixkh.sh
More file actions
65 lines (57 loc) · 2.21 KB
/
Copy pathfixkh.sh
File metadata and controls
65 lines (57 loc) · 2.21 KB
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
#!/bin/bash
#########################################################################
# fixkh.sh #
# Copyright (C) 2010 Psyjo #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 3 of the License, #
# 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 more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, see <http://www.gnu.org/licenses/>. #
#########################################################################
khFile="${HOME}/.ssh/known_hosts"
mkargs()
{
while [[ $# -gt 0 ]]
do
echo -n "($1)"
[[ $# -gt 1 ]] && echo -n "|"
shift
done
echo
}
Data="$(egrep "$(mkargs "$@")" ${khFile})"
sedStr='s/\(.\{80\}\).*\(.\{20\}\)$/\1[...]\2/p'
line="-----------------------------------------------------------------------------------------------------------------"
while : ;
do
[[ ! ${Data} ]] && { echo "Keine Daten vorhanden, beende."; exit 0; }
echo -e "zu ignorierende zeilen angeben, keine eingabe: ausfuehren\n${line}"
echo "${Data}" | sed -n "${sedStr}" | cat -n
echo "${line}"
read toDel
if [[ ${toDel} ]]
then
for n in $(echo ${toDel} | tr " " "\n" | sort -nr | tr "\n" " ")
do
Data=$(echo "${Data}" | sed "${n}d")
done
else break
fi
unset toDel
done
echo -e "\nloesche folgende...\n"
IFS=$'\n'
for l in ${Data}
do
echo "${l}" | sed -n "${sedStr}"
# echo "sed -i "$(grep -n "$(echo "${l}" | sed 's/\[/\\&/')" ${khFile} | awk -F: '{print $1}')d" ${khFile}"
sed -i "$(grep -n "$(echo "${l}" | sed 's/\[/\\&/')" ${khFile} | awk -F: '{print $1}')d" ${khFile}
done