Wednesday, December 1, 2010

Grep with filenames

Sometimes you want grep to tell you what files have a pattern within a directory.  Here is how to do it:


grep -H JAVA_HOME=/  /usr/local/terracotta/bin/* /usr/local/terracotta/platform/bin/*

/usr/local/terracotta/bin/start-tc-server.sh:export JAVA_HOME=/usr/java/jdk1.6.0_21/
/usr/local/bin/stop-tc-server.sh:export JAVA_HOME=/usr/java/jdk1.6.0_21/
/usr/local/bin/tim-get.sh:export JAVA_HOME=/usr/java/jdk1.6.0_21/
/usr/local/platform/bin/make-boot-jar.sh:export JAVA_HOME=/usr/java/jdk1.6.0_21/


Enjoy!

Wednesday, November 17, 2010

Bash for loops with a series of numbers or letters

Bash scripting is great. Here is a quick trick to funnel a series of numbers (or letters) into a variable, and thus an argument of a script:


#!/bin/bash
for a in {1..18}
do
echo "The number $a"
done


#!/bin/bash
for a in {a..z}
do
echo " The letter $a "
done

Here is another example:

for a in {0..15};  do  /usr/sbin/xm vcpu-pin 0 $a 0-1,4-15;  done


Such a quick and easy trick!

Thursday, July 22, 2010

Bring Netflix streaming to Linux!

Considering there are a host of devices (PS3, Roxee, TiVo, LG Blu-Ray players) that run Linux internally and support Netflix Streaming, it should be an easy technical transition to bring this to Linux.  Sign the petition to bring Netflix streaming to Linux. I am promoting it so I can use Netflix Streaming on my MythTV server and enhance the MythTV experience with Netflix streaming.

http://www.petitiononline.com/Linflix/petition.html

Friday, July 16, 2010

Create huge files fast with dd

Here is a quick way to create very large empty files without writing every byte using dd.

# dd if=/dev/zero of=largeemptyfile.img bs=1M count=1 seek=16999
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.001772 seconds, 592 MB/s
# ls -lh
total 1.1M
-rw-r--r-- 1 root root 17G Jul 16 09:07 largeemptyfile.img
# du -h
1.1M    .

Notice that the actual file is only 1.1 MB, but the file shows as 17GB.  This is because dd basically wrote the first and last parts of the file, and left the middle alone.  You can now use this file for anything, such as a Xen disk image.  Once it is in use, it will report as the full 17GB with du.

Thursday, July 8, 2010

Killing zombie processes

Kill those persistent and annoying zombie processes.


ps -e -o ppid,stat | grep Z | cut -d" " -f2 | xargs kill -9

Tested on Fedora for accuracy.  

New t-shirt shop

I have partnered with CafePress.com to create some suave t-shirts about tech.  See my shop at:

http://www.cafepress.com/Peachfuzztech

Enjoy!

Thursday, June 24, 2010

Sample /etc/dhcpd.conf configuration

Here is a basic dhcpd configuration.
For more info, look at /usr/share/doc/dhcp*/dhcpd.conf.sample.

ddns-update-style ad-hoc;

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option routers 192.168.1.1 ;
option domain-name "mydomain.com" ;
option domain-name-servers 4.2.2.2 4.2.2.3 ;
}

Friday, June 18, 2010

Make a service persistant on Ubuntu

The latest versions of Ubuntu (10.04 is where I noticed this behavior) ignore LSB configuration, which makes chkconfig not work for some scripts.  Instead, use update-rc.d-insserv to enable a service after reboot as shown.  This example enables the Samba services after a reboot.

update-rc.d-insserv nmbd defaults
update-rc.d-insserv smbd defaults

Thursday, June 17, 2010

Find the PID number with nothing else

Use this combination to find a PID number without anything else in the output:

ps -ef | grep -v grep | grep ssh | cut -d" " -f3
3012

Enjoy that kungfu knife-kick combo.

Thursday, May 27, 2010

Write on my Linux wall

To display a text message to other users logged into a *nix system, use the wall command. For example:

wall "Deploying new .ear file in five minutes."


This will send the message to all users logged into the system, whether they be physically on a console, via ssh or ftp.

Friday, January 8, 2010

Comment lines in vi

If you need to comment the next 10 lines within vi, execute the command within the command mode:

:.,+10s/^/#