Colored output with Python

Here's my stupid way of getting colored output from a Python script when run from the command line.

First, define one function per desired color:

{% highlight python %} def blue(message): return '\033[1;34m%s\033[1;m' % (message) def green(message): return '\033[1;32m%s\033[1;m' % (message) def red(message): return '\033[1;41m%s\033[1;m' % (message) def yellow(message): return '\033[1;33m%s\033[1;m' % (message) {% endhighlight %}

And then in the script, pass the message that you need to appear in color like this:

{% highlight python %} print red('File not found!') {% endhighlight %}

Note that if the Python script is meant to run via cron, then you will get some ugly text in emails from cron, since escape codes are not interpreted or removed from the output.

/etc/sysconfig/network-scripts/ifcfg-eth0

Example of a network interface configuration file:

# Hardware configuration:
UUID="46e26279-f69b-daf5-1b79-d03677b7178d"
HWADDR=00:1C:C0:0D:36:C6
DEVICE="p1p1"
TYPE="Ethernet"
ONBOOT="yes"
NAME=eth0
NM_CONTROLLED="no"

# IPv4 configuration:
BOOTPROTO="none"
IPADDR0="192.168.1.100"
PREFIX0="24"
GATEWAY0="192.168.1.1"
DNS1="192.168.1.53"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="yes"

# IPv6 configuration:
IPV6INIT="yes"
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

Parameters

BOOTPROTO
Can be set to dhcp if the interface will be automatically configured by a DHCP server, or to static if the interface will have a static IP configuration, or to none.
DEFROUTE
If set to yes, then during the activation of the interface, a default route towards the associated gateway will be added on the system.
HWADDR
The MAC Address of the interface, (HWaddr in the output of ifconfig), physically burnt on the device by the manufacturer.
NM_CONTROLLED
Whether or not the interface is controlled by the NetworkManager service. If set to no, the operation of the interface needs to be controlled elsewise, e.g. with running the network service in the place of NetworkManager.
ONBOOT
Whether or not the interface should be activated automatically during system startup.

Install Motion on CentOS 6

These are some very very brief instructions on how to install Motion on a CentOS 6 system.

Install Prerequisites

yum -y install gcc make
yum -y install libjpeg-turbo libjpeg-turbo-devel

Install Motion

Download Motion, e.g. as a .tgz from SourceForge:

cd /root/
wget http://downloads.sourceforge.net/project/motion/motion%20-%203.2/3.2.12/motion-3.2.12.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmotion%2Ffiles%2Fmotion%2520-%25203.2%2F3.2.12%2F&ts=1385393313&use_mirror=garr

Untar:

tar zxvf motion-3.2.12.tar.gz

Install:

cd /root/motion-3.2.12/
./configure
make
make install

This will install motion in its default location, in subdirectories of /usr/local/, e.g:

  • /usr/local/bin/ for executables,
  • /usr/local/man/ for man pages,
  • /usr/local/etc/ for configuration files,
  • /usr/local/docs/ for documentation,
  • /usr/local/share/ for configuration examples, etc.

Finally, before starting motion you need to copy the default configuration file motion-dist.conf to motion.conf (by default in /usr/local/etc/.

Preparing a new CentOS 6 Server

These are some reminders to myself, to apply my personal preferences when installing a new server based on CentOS 6.

  1. Make booting verbose, remove the portion rgbh quiet from the kernel line in /boot/grub/grub.conf.

  2. Install misc tools:

    yum -y install vim
    yum -y install wget
    yum -y install mlocate
    yum -y install iptraf
    yum -y install iotraf
    yum -y install man
    yum -y install nmap
    
  3. CRON Configuration: Sometimes fresh Minimal CentOS installations don't come with Cron pre-installed. In such a case:

    yum -y install cronie cronie-anacron crontabs
    

    Then activate and enable the service:

    chkconfig crond on
    service crond start
    
  4. SNMP Configuration:

    yum -y install net-snmp
    chkconfig snmpd on
    

    In /etc/snmp/snmpd.conf change the community to something other than the default public, for example change the line:

    com2sec notConfigUser  default       public
    

    To something like:

    com2sec notConfigUser  default       My_pr1vate_c0mmunity
    

    Also, if you are using an NMS like Zenoss that can poll all sorts of information from the device via SNMP, you can greatly expand the range of data available with commenting out the following two lines...

    view    systemview    included   .1.3.6.1.2.1.1
    view    systemview    included   .1.3.6.1.2.1.25.1.1
    

    ...and substituting them with:

    view    systemview    included   .1
    
  5. Disable console blanking by editing /boot/grub/grub.conf and adding the following at the end of the kernel line:

    consoleblank=0
    

Sources

Flowchart and Diagram Editors

Online Flowchart and Diagram Editors

  • Google Docs has a Drawing application that can be used to create diagrams.
  • Gliffy can also create several types of diagrams, and is free for a limited amount of documents.
  • LucidChart is another online diagram editor, and is also free with some restrictions.

See Also

syslog-ng

GUIs compatible with syslog-ng

tcpdump

Notes and links on tcpdump.

Capture and output at the same time

This command will make tcpdump save captured packets in a .pcap file, and output their printable format on stdout:

sudo tcpdump -n -s0 -U -vvv tcp port 80 -w - | tee capture.pcap | tcpdump -vvv -n -r -

Options:

-n  : numeric output, don't resolve IPs to names, don't resolve ports to service names
-s0 : don't truncate packets unless they are bigger than 65535 bytes
-U  : don't buffer output, dump to `.pcap` immediately
-w  : write `.pcap`
-r  : read from `.pcap`

See Also

About

Hello, I'm Marios Zindilis and this is my website. Opinions are my own. You also find me on LinkedIn and GitHub.

Unless otherwise specified, content is licensed under CC0.

Search