Wednesday, December 14, 2011

Make script compatible with chkconfig

To make an init script compatible with chkconfig (to autostart on next runlevel change), add the following header to your script within it's /etc/init.d/ file, for example, /etc/init.d/myscript

#!/bin/bash

#
# myscript     init script to manage myserver
#
# chkconfig: 2345 90 35
# description: A server which does amazing things.
#


Now, add it with these commands:

/bin/chmod +x  /etc/init.d/myscript
/sbin/chkconfig myscript --add
/sbin/chkconfig myscript on
/sbin/chkconfig myscript --list
myserver       0:off    1:off    2:on    3:on    4:on    5:on    6:off


Within the chkconfig definition line, 2345 means the runlevels it will be started under, and 90 35 are the start and kill priorities, an integer between 0 and 99.  In this example, it would be started as one of the last services, and killed (stopped) as one of the earlier processes.

Tuesday, November 29, 2011

Just kill the process

/bin/kill -9 `/bin/cat /var/run/snmpd.pid`

To kill just the PID reported by the process as the active PID (with a shotgun, -9) and nothing else, use this shortcut.

Thursday, November 3, 2011

sed add line at end of file

If you want to add a a line of text to the end of a file, and want to do the edit in place, use this syntax:

sed -i '$ a\This is some sample text.'  /foo/bar

Monday, October 31, 2011

Visual explanation of SQL joins

I wish I had these pictures in my head when I started learning about joins in SQL.  Might have been a DBA instead of a systems engineer.


http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

Sunday, October 9, 2011

Charge iPad or iPad2 over usb in Linux

First, follow these instructions:

http://korenkov.info/ipad-ipad2-charge-ubuntu

For later versions of udev (I tested this on Ubuntu 11.04), make sure that /etc/udev/rules.d/95-ipad_charge.rules looks like the following examples.

For iPad:

ENV{DEVTYPE}=="usb_device", ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="129a", RUN+="/usr/bin/ipad_charge"

For iPad2:

ENV{DEVTYPE}=="usb_device", ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="129f", RUN+="/usr/bin/ipad_charge"

Then restart udev or reboot.

Monday, July 25, 2011

sed with variables

Here is an example of how to get sed to replace values within files with variables:

for a in {1..12} ; do sed -e s/0/"$a"/g myConfig > myConfig$a ; done;


This is useful if you need to have an iterated set of config files, for instance.

In place editing of files quickly

Use the sed -i option for in place editing of files:

sed -i 's/foo/bar/g' FILENAME

It will replace all occurances of foo with bar within FILENAME

Monday, July 11, 2011

Convert videos to iPad 2 format

Recorded programs on my MythTV are in a lossless HD mpg format, which doesn't play well on my iPad2 using AirVideo Server over wlan (via wine). So, instead of having AirVideo Server converting it through the wine abstraction layer (which requires more CPU/memory, and uses ffmpeg.exe anyway), I just run this user job from my MythTV server to convert the files that I care to watch on my iPad.

Step 1:
Create this file which I call /usr/bin/mythconverttoipad. If you have an issue with "too may threads," remove -threads 16. I am using this script on a 3 core machine, the -threads option speeds things up a bit.

#!/bin/bash
DIR=$1
FILE=$2

echo $DIR
echo $FILE

ffmpeg -y -i $DIR/$FILE -ab 320kb -vcodec libx264 -b 3200kb -s 1280x720 -threads 16 $DIR/$FILE.m4v


Step 2:
Make the script executable.

chmod +x /usr/bin/mythconverttoipad

Step 3:
Add script as user job within MythTV.

Within mythtv-setup add the following user job:

/usr/bin/mythconverttoipad %DIR% %FILE%

Step 4:

Enable it within rules.

Within a program recording rule (within mythfrontent), enable this user job to be run post-recording.

Step 5:
Access the files from Air Video client or other player.

If you have questions, please comment.

Tuesday, June 7, 2011

Control Roku player over telnet

My young boys have broken several remotes for my Roku player. I am tired of buying new ones. There is a way to control the Roku player over the network, though. Use telnet on port 8080, for example:

[root@mythtv3 ~]# telnet 192.168.1.8 8080
Trying 192.168.1.8...
Connected to 192.168.1.8.
Escape character is '^]'.
H0A0AC134945
ETHMAC 00:0d:4c:43:90:11
WIFIMAC 00:0d:4c:43:90:11
>press right
>press down
>press select

The available commands are:
press up
press down
press left
press right
press select
press home
press fwd
press back
press pause


Additional information:

http://forums.roku.com/viewtopic.php?t=20106

Tuesday, April 26, 2011

Install capistrano on RHEL or CentOS

Capistrano is great for automating system tasks. Here is how to install it on RPM-based systems:

# yum install ruby rubygems
# gem install mocha echoe rake capistrano

Please note that mocha, echoe are optional for tests, but I included them in these instructions.

Monday, April 18, 2011

TCP dump for only port 80

Here is a way to dump all tcp traffic on port 80 to and from the bond0 interface:

tcpdump -w tcpdumpPort80.pcap -i bond0 tcp port 80

If you wanted to use only the eth0 interface (more common), use this example:

tcpdump -w tcpdumpPort80.pcap -i eth0 tcp port 80

Sending files from the Linux command line

Here is a quick way to e-mail yourself files from a server using mutt.

$ mutt -a tcpdumpApril182011.pcap my_name@example.com < /dev/null

Mutt is great for sending MIME encoded files.

Monday, March 7, 2011

Quickly clear out a file's contents

If you ever have the need to quickly clear out the contents of a file while preserving its priviledges and creation date, use this command:

echo " " > myConfig.xml

or

echo " " > /etc/my.cnf