I have an expect script that I want to run at startup. Among other things it configures a few serial ports. When I run it via systemd I get:

couldn't read file "/dev/tty": no such device or address while executing exec /bin/stty -F /dev/ttyACM0 ... </dev/tty

I figure this is because systemd runs services as processes without a controlling terminal, but is there a way around the problem? The script that gets called has no reference to /dev/tty:

stty -F /dev/ttyACM0 ...

  • You would have helped answerers significantly had you mentioned that this is an expect script, not a shell script, and indeed not cut that out of the error message. – JdeBP Dec 3 '18 at 15:45
  • There's nothing in the error message about an expect. Parts of the script indeed use expect, though not the stty part explicitly. But yes, it's true the script is called with expect. I didn't realize it was significant. – user907323 Dec 3 '18 at 16:08

You have two ways to tell stty which tty to configure, either use -F /dev/your_tty, or redirect stdin as in < /dev/your_tty.

Using both makes no sense. Just get rid of the < /dev/tty at the end.


With your edit: Now the question is why an stty call is translated into one with < /dev/tty in the first place.

  • Right. Where do the exec and /dev/tty come from? – user907323 Dec 3 '18 at 14:46
  • First thing I'd do is to looking at the complete service description file for what you are doing. Second thing I'd do is look closely at the script. – dirkt Dec 3 '18 at 14:48
  • Third option is to check if stty without a path somehow is a script, alias etc. which expands to /bin/stty ... < /dev/tty. – dirkt Dec 3 '18 at 14:49
  • [Unit] Description=script [Service] Type=simple ExecStart=script.sh Restart=no After=some services [Install] WantedBy=multi-user.target – user907323 Dec 3 '18 at 14:50
  • $ strace stty gives: execve("/bin/stty", ["stty"], [/* 20 vars */]) = 0 -- doesn't look like option 3 – user907323 Dec 3 '18 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.