mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-03-20 01:37:45 +01:00
cleanup and final comments
This commit is contained in:
parent
53f2f2c3ac
commit
2feb276f2f
@ -1,20 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Deletes certain lines of ~/.ssh/known_hosts
|
# Deletes certain lines of ~/.ssh/known_hosts
|
||||||
|
|
||||||
# Check if any args passed
|
# Check if any args passed
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
echo "Usage: ./delete_certain_known_hosts 3 5 7 23"
|
echo "Usage: ./delete_certain_known_hosts 3 5 7 23"
|
||||||
echo "Will catch duplicate line numbers"
|
echo "Will catch duplicate line numbers"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
# Set variables
|
||||||
# Set loop variables
|
|
||||||
known_hosts_path=~/.ssh/known_hosts
|
known_hosts_path=~/.ssh/known_hosts
|
||||||
lines_in_known_hosts=$(wc -l "$known_hosts_path" | awk '{print $1}')
|
lines_in_known_hosts=$(wc -l "$known_hosts_path" | awk '{print $1}')
|
||||||
|
lines_to_delete=""
|
||||||
|
# Dedupe, sort numerically, and create array from args string
|
||||||
IFS=' '
|
IFS=' '
|
||||||
deduped_args=$(echo "$@" | xargs -n1 | sort -nu | xargs)
|
deduped_args=$(echo "$@" | xargs -n1 | sort -nu | xargs)
|
||||||
read -r -a delete_these_lines <<< "$deduped_args"
|
read -r -a delete_these_lines <<< "$deduped_args"
|
||||||
lines_to_delete=""
|
# Loop through creating sed expression
|
||||||
for var in "${delete_these_lines[@]}"; do
|
for var in "${delete_these_lines[@]}"; do
|
||||||
if [[ "$var" -gt "$lines_in_known_hosts" ]]; then
|
if [[ "$var" -gt "$lines_in_known_hosts" ]]; then
|
||||||
echo "$var is invalid line in $lines_in_known_hosts line $known_hosts_path"
|
echo "$var is invalid line in $lines_in_known_hosts line $known_hosts_path"
|
||||||
@ -22,7 +22,6 @@ else
|
|||||||
lines_to_delete+="${var}d;"
|
lines_to_delete+="${var}d;"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Output information to user about what happened
|
# Output information to user about what happened
|
||||||
if [[ -z "$lines_to_delete" ]]; then
|
if [[ -z "$lines_to_delete" ]]; then
|
||||||
echo "All arguments passed were invalid lines in $known_hosts_path"
|
echo "All arguments passed were invalid lines in $known_hosts_path"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user