HOWTO Redirect Linux Console Without Reboot

You can re-apply your /etc/inittab file in real-time without rebooting your machine. This allows you to do a lot of neat things, such as redirect your system console to the serial port without a reboot.

  1. Edit your /etc/inittab file and add this line:
    • S0:12345:respawn:/sbin/agetty -L 9600 ttyS0 vt102
  2. Execute the following command:
    • telinit q && telinit u
  3. Your primary console (ttyS0) should magically appear on the serial console!

So what just happened? The /etc/inittab file is read by the init system at boot. If you added the line from step 1 and simply rebooted, you would have your console show up on the serial port right away. We told init to re-read the /etc/inittab file (telinit q) and then to re-execute itself (telinit u) while preserving the init state. Since the only change was the location of ttyS0, the console was redirected, but the system continued to run as though nothing else changed.

The reason we used the && method was because we may loose our console before we get a chance to execute telinit u. This way both commands are run and init is always executed after re-reading its config.

Did you find this post useful or have questions or comments? Please let me know!

Posted in How Tos, linux | Leave a comment

HOW TO detect STDIN with Python

In Python, as with most languages, STDIN is treated like a file. You can read from it any time, but knowing what kind of file it is lets us know if someone passed us something via STDIN or if we are going to prompt them for it.

import os, sys

if os.isatty(file.fileno(sys.stdin)):
    print "Reading list from STDIN."
    print "Enter your list. Press ^D to continue, ^C to quit."
    my_list = sys.stdin.readlines()
else:
    print "Thank you for passing me a list through a pipe."
    my_list = sys.stdin.readlines()

Now lets try it two ways:

First, pass it some stuff:
echo mother sister father brother | ./myapp.py

Then try it plain:
./myapp.py

Did you find this post useful or have questions or comments? Please let me know!

Posted in How Tos, Programming, python | 2 Comments

HowTo Use an HTTP Proxy With Git

git should use the environment variable $http_proxy so set that and you should be ok. If you don’t want to use the environment, set it statically like this:

$ git config --global http.proxy http://proxy.example.com:8080
$ git config --get http.proxy
http://proxy.example.com:8080

Posted in git, How Tos, Programming | Leave a comment