diff --git a/.gitignore b/.gitignore index 5acc090..7d82063 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.lock -caddy_docker_custom_user/run_* \ No newline at end of file +caddy_docker_custom_user/run_* +.motd.services +.motd.users diff --git a/motd.sh b/motd.sh index d6d19d6..1440cee 100755 --- a/motd.sh +++ b/motd.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash +dir=$(dirname "$0") ### Time and date ### echo -e "$(date)" @@ -11,7 +12,8 @@ echo -e ### System info ### echo -e "$(cat /etc/*release | grep PRETTY_NAME | cut -d = -f 2- | sed 's/\"//g') | Kernel: $(uname -r)" -echo -e "Uptime: $(uptime -p | sed 's/up //')" +uptime=$(uptime | awk -F'( |,|:)+' '{d=h=m=0; if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}') +echo -e "Uptime: ${uptime}" echo -e ### Colors ### @@ -32,7 +34,7 @@ redbg="\e[41m" greenbg="\e[42m" ### Services ### -services=($(cat /.motd.services)) +services=($(cat "$dir/.motd.services")) # sort services #IFS=$'\n' services=($(sort <<<"${services[*]}")) #unset IFS @@ -68,7 +70,7 @@ for i in ${!containers[@]}; do done docker_out+=" [rootless]\n" -rootless_users=($(cat /.motd.users)) +rootless_users=($(cat "$dir/.motd.users")) for user in ${rootless_users[@]}; do if sudo test ! -e /run/user/$(id -u $user)/docker.sock; then