On some of my server systems (Debian trixie), wifi power saving causes "laggy" terminal response on the client side of the SSH connection. By "laggy" I mean that there is an annoying latency between the time I press a key on the keyboard, and when I see the feedback in my SSH-wifi-connected client terminal. I've found that disabling wifi power saving on the server reduces this latency to (effectively) zero. And so my "solution" has been to disable the power saving feature in a cron job that runs @reboot; i.e. turn power_save off, and leave it off.
But that "leave it off" solution feels like a wasted opportunity to save a little power. Instead, I've reasoned that wifi power_save should be dependent on SSH-wifi remote-user logins; i.e. wifi power_save should be "on" if there are no SSH-wifi logins, and "off" if there are one or more active pts.
And so I wrote a short script to turn wifi power_save off or on depending upon the number of pts counted in ~/.bash_logout and ~/.bash_login:
- in
~/.bash_logout:
if [[ $(w -h | grep pts | wc -l) == "1" ]]; then
sudo /usr/sbin/iw wlan0 set power_save on
fi
I used "1" in the test (instead of "0") as it seems that the user is not actually logged out until after ~/.bash_logout has exited. This seems to "work" wrt setting power_save to "on".
I've hit a snag in ~/.bash_login - not because of the script itself (which seems to work fine), but in the information displayed by a script in /etc/update-motd.d which displays the power_save status at user login.
- in
~/.bash_login:
if [ "$(w -h | grep pts | wc -l)" == "1" ]; then
sudo /usr/sbin/iw wlan0 set power_save off
fi
. /home/my/.bashrc
What I see for my MOTD:
WiFi PwrSv Power save: on
However, if I run iw wlan0 get power_save after my login, it reports Power save: off - in accordance with the ~/.bash_login script. IOW - the problem seems to be that the output of /etc/update-motd.d is generated before ~/.bash_login is run. FWIW, this is IAW some output I got from asking the question here. Also FWIW, according to this "vintage" Debian wiki, /etc/update-motd.d is run by pam_motd.
And so my question is: "How can I 're-arrange' the order of execution of /etc/update-motd.d and ~/.bash_login to get a correct MOTD output?
ss -tn|awk '$5~/:22$'... for the former the same w/$4instead.