setterm errors over ssh and when running in systemd service

Issues related to applications and software problems and general support
Post Reply
xnobodyx
Posts: 11
Joined: 2020/05/25 01:52:51

setterm errors over ssh and when running in systemd service

Post by xnobodyx » 2021/07/14 22:38:05

hello,

i can set the screen on a laptop to turn off after 1 minute with:

Code: Select all

setterm -blank 1 -powersave powerdown
i can't seem to get it to work over ssh. i am logged in locally on the machine to tty1 as verified by running $ w .

the solutions i've seen seem to indicate redirecting the command in the ssh session to tty1:

Code: Select all

sudo setterm -blank 1 -powersave powerdown >/dev/tty1
however this is returning the error:

"setterm: terminal xterm does not support --blank
setterm: cannot (un)set powersave mode: Inappropriate ioctl for device"

any help is greatly appreciated
Last edited by xnobodyx on 2021/07/14 23:15:30, edited 2 times in total.

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: setterm errors over ssh

Post by TrevorH » 2021/07/14 22:50:17

i am logged in locally on the machine to tty1 as verified by running $ w .
I suspect someone is logged in as root on tty1. If you're in via ssh, unless you've done some "interesting" stuff then you'll be on pts/n. Try running who am i in your ssh session - does that say tty1? I'll also guess that if you run echo $TERM it says 'xterm'. Try TERM=linux setterm -blank 1 -powersave powerdown >/dev/tty1 (you will need to be root to run that).
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

xnobodyx
Posts: 11
Joined: 2020/05/25 01:52:51

Re: setterm errors over ssh

Post by xnobodyx » 2021/07/14 22:56:54

thanks for the quick reply. i was under the impression i would need to be logged in to tty1 locally on the machine to send the command from the ssh console to tty1?

(for the record, i run 'setterm -blank 0 -powersave off' locally on the machine before each test)

echo $TERM does return xterm in the ssh session.

TERM=linux setterm -blank 1 -powersave powerdown >/dev/tty1 returns the same "setterm: cannot (un)set powersave mode: Inappropriate ioctl for device" but it also appears to work, the screen powers off after one minute.

on a related note i am also trying to set up a systemd service to run the same command on boot...it seems to be working but outputs the same "setterm: cannot (un)set powersave mode: Inappropriate ioctl for device" error

Code: Select all

[Unit]
Description=Enable virtual console blanking and poweroff

[Service]
Type=oneshot
Environment=TERM=linux
StandardOutput=tty
TTYPath=/dev/console 
ExecStart=/usr/bin/setterm -blank 1 -powersave powerdown

[Install]
WantedBy=default.target
- Source: https://access.redhat.com/documentation ... m-settings
- Source: http://archlinux.2023198.n4.nabble.com/ ... 19304.html

xnobodyx
Posts: 11
Joined: 2020/05/25 01:52:51

Re: setterm errors over ssh

Post by xnobodyx » 2021/07/14 22:59:57

ah TERM=linux setterm -blank 1 -powersave powerdown >/dev/tty1 </dev/tty1 appears to have fixed it for the ssh session...does that seem right?

not sure how to implement that in the system service though...

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: setterm errors over ssh

Post by TrevorH » 2021/07/14 23:06:30

Well we could probably much about experimenting with a unit file like that for a long time before we found the correct incantation so I think I'd write a 3 line shell script and stick it in /usr/local/bin and start that from the unit file...
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

xnobodyx
Posts: 11
Joined: 2020/05/25 01:52:51

Re: setterm errors over ssh

Post by xnobodyx » 2021/07/14 23:10:50

sadly i was trying that approach and it was failing, will try it again. thanks very much for your help

to clarify the screen does power off after the service is started, it just prints that error...

xnobodyx
Posts: 11
Joined: 2020/05/25 01:52:51

Re: setterm errors over ssh and when running in systemd service

Post by xnobodyx » 2021/07/14 23:33:54

unfortunately still getting the same 'Inappropriate ioctl for device' using the following script and service. to clarify if i login and run setterm -blank 1 -powersave powerdown there is no error:

/usr/local/bin/screenblank.sh:

Code: Select all

#!/bin/sh
TERM=linux setterm -blank 1 -powersave powerdown >/dev/console </dev/console
and /etc/systemd/system/screenblank.service:

Code: Select all

[Unit]
Description=Enable virtual console blanking and poweroff

[Service]
Type=oneshot
Environment=TERM=linux
StandardOutput=tty
TTYPath=/dev/console 
ExecStart=/usr/local/bin/screenblank.sh

[Install]
WantedBy=default.target

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: setterm errors over ssh and when running in systemd service

Post by TrevorH » 2021/07/14 23:44:39

Run aureport -a and see if you have any entries in the audit log that match the time you last tried. If you do then use the number off the right hand end of that and plug it into ausearch -a nnnn and see if that helps explain it.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

xnobodyx
Posts: 11
Joined: 2020/05/25 01:52:51

Re: setterm errors over ssh and when running in systemd service

Post by xnobodyx » 2021/07/14 23:51:13

unfortunately nothing in the audit log

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: setterm errors over ssh and when running in systemd service

Post by TrevorH » 2021/07/15 10:15:42

Well the only difference I can see from the command you say worked when you ran it manually and the unit file is that the one that worked, you used /dev/tty1 and in your unit file you use /dev/console.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply