0

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?

3
  • It's not clear whether the machine you're connecting to is using powersaving wifi, or the one you're working on; for the latter I'd use ss -tn|awk '$5~/:22$' ... for the former the same w/ $4 instead. Commented 2 days ago
  • @tink Usually it's the remote (SSH destination) machine. Wi-fi power saving on the client is rarely an issue as its interface is awoken by the host to send your keypress first and then remains awake for enough time to receive a reply. On the server, though, the interface is asleep when your keypress packet needs to arrive so there's noticeable latency until it wakes up. Commented yesterday
  • Server's on WiFi are a strange concept to me, that's all ... ;) @grawity Commented yesterday

1 Answer 1

0

Use PAM to run your script too. Insert a pam_exec into the "session" section of /etc/pam.d/sshd or any other remote service. It'll be called with different $PAM_TYPE when the session is opened and when it is closed.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.