Skip to content

Commit

Permalink
Try to infer login hostname from /etc/hosts, if only an IP number was…
Browse files Browse the repository at this point in the history
… found
  • Loading branch information
HenrikBengtsson committed Oct 4, 2023
1 parent c285203 commit bd7f940
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Version (development version)

* ...
### Miscellaneous

* `rsc start` attempts to infer the login hostname from ``etc/hosts`,
if it only finds an IP number at first.


## Version 0.13.6 [2023-06-22]
Expand Down
11 changes: 9 additions & 2 deletions bin/rsc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
### rsc config --full
### rsc log
###
### Version: 0.13.6-9000
### Version: 0.13.6-9001
### Copyright: Henrik Bengtsson (2022-2023) and Harry Putnam (2022)
### License: ISC

Expand Down Expand Up @@ -554,7 +554,14 @@ function find_login_host_via_who {
## Extract the hostname
bfr=$(echo "${bfr}" | sed -E 's/(.*[[:space:]]+[(]|[)][[:space:]]*)//g')
mdebug "4. ${bfr}"
fi
## If hostname is an IP number, try to identify hostname
if grep -q -E "^[[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+$" <<< "${bfr}"; then
if [[ -f /etc/hosts ]] && grep -q -E "\b${bfr}\b" /etc/hosts; then
bfr=$(grep -E "\b${bfr}\b" /etc/hosts | sed -E "s/\b${bfr}\b//g" | sed -E 's/[[:space:]]+/ /g' | sed -E 's/(^ | $)//g' | cut -d ' ' -f 1)
fi
mdebug "5. ${bfr}"
fi
fi
echo "${bfr}"
}

Expand Down

0 comments on commit bd7f940

Please sign in to comment.