Question

Below is the inittab file entry for starting shell.

::respawn:/bin/bash < /dev/ttyS0 > /dev/ttyS0 2> /dev/ttyS0

My question is, I am reading a config file which says on which tty port /bin/bash needs to respawned. File content may be ttyS0, ttyS1 or ttyS2.

How can I respawn /bin/bash based on file content.

Was it helpful?

Solution

Assuming your config file is /etc/dynshell.cfg and contains the device name (like ttyS0) on one line, and nothing else, you can write this…

#!/bin/sh
port=/dev/$(</etc/dynshell.cfg)
exec /bin/bash <$port >$port 2>$port

… into /usr/local/sbin/dynshell, then use this line:

::respawn:/usr/local/sbin/dynshell

Although this might be better/safer:

#!/bin/sh
port=/dev/$(</etc/dynshell.cfg)
exec /bin/bash 0<>$port >&0 2>&0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top