Linux: Counting the number of lines inside multiple files

Posted by & filed under BASH, Programming.

Recently I needed to recursively count the number of lines of code in each of the specific file types. In this instance I wanted to count the number of lines of code in my PHP files. The below command worked flawlessly. In addition to breaking down the line count in each directory, it gives a overall total at the end as well.

Pipe Viewer

Posted by & filed under BASH, Programming, Server Admin.

pv – Pipe Viewer – is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion.

www.ivarch.com/programs/pv.shtml

Linux: Find files modified between dates

Posted by & filed under BASH, Linux.

I found a handy technique to find files modified between a specific date. In essence, we touch two temp files, setting the modified dates to the range we want to find:

Note the date is yyymmddtime.

Then we run the find command:

Done!

Recursive directory search for string

Posted by & filed under BASH, Linux.

The following command will search for a string within files in a directory recursively.

sudo find . -type f -print0 | xargs -0 grep -n 'STRING TO SEARCH FOR'

Stream audio over SSH

Posted by & filed under BASH, Linux.

Ok this is sweet:

ssh user@server.com “cat /Torrents/Complete/15\ years\ of\ Essential\ Mix\ Sasha\ \&\ Digweed/Essential\ Mix\ 137\ -\ Sasha\ -\ Live\ @\ radio\ 1\ on\ tour\ from\ Sanctuary\ -\ [30.06.1996].mp3” | mpg123 –

And here is a more advanced version to find multiple files (unworking)
ssh user@server.com “find /Torrents/Complete -wholename \*Essential\*.mp3 -print0 | xargs -0 cat” | mpg123 –

this finds fines in /Torrents/Complete and pipes them to mpg123

Monitoring a Linux process by PID and sending a e-mail notification upon failure

Posted by & filed under BASH, Email, Linux, Programming.

One of my clients needs their vendor to be alerted when their Backup Exec service crashes. I wrote the following quick-n-dirty batch script intended to be ran as a cron job.

And the cron line would be something like this: