Skip to content

Commit

Permalink
Now 'ucsf vpn status' reports also how long ago the OpenConnect proce…
Browse files Browse the repository at this point in the history
…ss was started [#36]
  • Loading branch information
HenrikBengtsson committed May 14, 2024
1 parent 79b49e6 commit ac3e4f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ucsf-vpn
* Now `ucsf vpn start --debug` and `ucsf vpn stop --debug` reports on
changes to your IP routing table (per `ip route show`).

* Now `ucsf vpn status` reports also on when the OpenConnect process
was started, if it exists.
* Now `ucsf vpn status` reports also on how long ago and when the
OpenConnect process was started, if it exists.

* Now `ucsf vpn` gives an error if it detects an unknown `--<flag>`
or an unknown `--<key>=<value>` option.
Expand Down
14 changes: 11 additions & 3 deletions bin/ucsf-vpn
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
### * UCSF Managing Your Passwords:
### - https://it.ucsf.edu/services/managing-your-passwords
###
### Version: 5.7.0-9017
### Version: 5.7.0-9018
### Copyright: Henrik Bengtsson (2016-2024)
### License: GPL (>= 2.1) [https://www.gnu.org/licenses/gpl.html]
### Source: https://github.com/HenrikBengtsson/ucsf-vpn
Expand Down Expand Up @@ -468,7 +468,7 @@ function status() {
local -a connected
local method
local oldIFS
local timestamp
local timestamp now since s m h age

assert=$1
mdebug "status() ..."
Expand All @@ -495,8 +495,16 @@ function status() {
timestamp=$(ps -p "${pid}" -o lstart=)
if [[ -n ${timestamp} ]]; then
timestamp=$(date -d "${timestamp}" --iso-8601=seconds)
since=$(date -d "${timestamp}" +%s)
now=$(date +%s)
s=$((now - since))
m=$((s / 60))
s=$((s - 60 * m))
h=$((m / 60))
m=$((m - 60 * h))
age=$(printf "%02dh%02dm%02ds" "${h}" "${m}" "${s}")
fi
msg="'openconnect' process running (started on ${timestamp}; PID=${pid})"
msg="'openconnect' process running (started ${age} ago on ${timestamp}; PID=${pid})"
fi
msgs+=("OpenConnect status: $msg")
elif [[ $method == ipinfo ]]; then
Expand Down

0 comments on commit ac3e4f6

Please sign in to comment.