First post here. I'm trying to run some tests against a CentOS 6 machine, but my tests disable networking so I communicate over serial ports.

I created an upstart job that sets up ttyS1 such that it has a bash root shell on it. I used:

/sbin/agetty -n -l /bin/bash ttyS1 115200 vt102

This is a hack, running /bin/bash as a login program. It works, but I would like to pass --rcfile to /bin/bash (otherwise, I get some undesirable output of "bash: /root/.bashrc: Permission denied", even though it is being run as root).

Note: the version of agetty being used has neither --version nor --login-options.


agetty expects a program to run for the -l option. You could make that (for instance) a Perl script, and make that provide the parameters, e.g., call this script myshell

exec 'bash --rcfile myprofile'

and use the pathname of myshell in the agetty command.

I used Perl because it does not read your bash (or sh) profile. If you use a script that runs /bin/sh, it can read the user's .profile (which seemed contrary to your intent). The exec feature is provided in other scripting languages (including sh and bash).

  • I already attempted another script to no avail. #!/bin/sh /bin/bash --rcfile /etc/bashrc I didn't try exec /bin/bash ... though. – Scott Crunkleton Nov 10 '16 at 1:46
  • I wonder if agetty can even run a script as a login program, or if it only allows binaries. – Scott Crunkleton Nov 10 '16 at 1:54
  • It doesn't matter: agetty is using an exec (C runtime) call which only asks the kernel to run whatever that pathname is. – Thomas Dickey Nov 10 '16 at 2:04

You may think it is overkill, but rather than using getty and running a shell on the serial line, you could try using SLIP, Serial Line Internet Protocol. This turns your serial port into a network interface over which you can connect multiple logins simultaneously using ssh or whatever, send files using rsync, and so on, all with the advantage of reliability and error detection.

It is simple to setup and use, assuming your kernel supports it (usually the case). The easiest way is with the slattach command, which is usually in the net-tools package. On one machine give the commands

sudo slattach -p cslip -s 19200 /dev/ttyS0 &
sudo ifconfig sl0 pointopoint

where the first command specifies the baud rate and serial device, and the second provides the IP address of that machine, and of the other machine. On the other end give the same commands, swapping over the 2 IP addresses. Choose a set of addresses that you are not already using.

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.