secured rmhost

This commit is contained in:
Geoffray Levasseur-Brandin
2025-06-19 14:39:10 +02:00
parent 87dea45295
commit ff4c6702b7

View File

@@ -47,9 +47,9 @@ rmhost()
while [[ $1 ]]; do while [[ $1 ]]; do
local hst=$1 && shift local hst=$1 && shift
isipv4 $hst >/dev/null isipv4 "$hst" >/dev/null
local v4=$? local v4=$?
isipv6 $hst >/dev/null isipv6 "$hst" >/dev/null
local v6=$? local v6=$?
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
@@ -59,10 +59,14 @@ rmhost()
unset v4 v6 unset v4 v6
if [[ ! $ip && $hst ]]; then if [[ ! $ip && $hst ]]; then
ip=$(host $hst | grep "has address" | awk '{print $NF}') if ! ip=$(host "$hst" 2>/dev/null | awk '/has address/ {print $NF; exit}'); then
[[ ! $? ]] &&
disp E "Impossible to extract IP from hostname." && disp E "Impossible to extract IP from hostname." &&
return 1 return 1
fi
[[ -z $ip ]] && {
disp E "Impossible to extract IP from hostname."
return 1;
}
fi fi
if [[ $hst ]]; then if [[ $hst ]]; then
@@ -94,13 +98,17 @@ ssr()
esac esac
done done
command -v ssh >/dev/null 2>&1 || {
disp E "ssh is not installed."
return 127
}
[[ ! $1 ]] && [[ ! $1 ]] &&
disp E "Please specify the server you want to log in." && disp E "Please specify the server you want to log in." &&
return 1 return 1
local srv=$1 && shift local srv=$1 && shift
ssh -Y root@$srv $@ ssh -Y root@"$srv" "$@"
} }
export -f ssr export -f ssr