What is the best way of automating on/off switch for a usb serial device
via ttyU? One solution would be a script accessible via visudo (see
init_ttyU below). The idea is not to do the following by hand, but
automate it. Are there any security risks involved by automating it?
1. su to root
2. edit on/off in /etc/ttys
ttyU0 "/usr/libexec/getty std.9600" vt100 on secure
3. kill -HUP 1 to restart init & getty's
Solution for on:
1. Attach usb serial, check dmesg
2. Run `init_ttyU on`
Solution for off:
1. Run `init_ttyU off`
2. Detach usb serial
Note: We always switch ttyU? off before switching it on. If the device
is detached whilst on, the getty ttyU? process can disappear. Before
init can switch it on, it needs to switch it off.
init_ttyU
=========
#!/bin/sh
if [[ $# -ne 1 || ! ($1 = "off" || $1 = "on") ]] then
echo "Usage $0 on or $0 off"
exit 1
fi
tmp=/tmp/ttyU$$
/usr/bin/sed /^ttyU[01]/s/on/off/g /etc/ttys > $tmp
if [[ -s $tmp ]] then
/bin/cat $tmp > /etc/ttys
fi
/bin/kill -HUP 1
if [[ $1 = "on" ]] then
/usr/bin/sed /^ttyU[01]/s/off/on/g /etc/ttys > $tmp
if [[ -s $tmp ]] then
/bin/cat $tmp > /etc/ttys
fi
/bin/kill -HUP 1
fi
rm -rf $tmp
Ed.