Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts

Friday, 5 April 2013

Bash script to download Infinite Monkey Cage episodes.

Hi all,

It's been a while but I thought I might share this with you.
I am a fan of a BBC Radio 4 show called "The Infinite Monkey Cage". Hosted by Prof. Brian Cox no less.

Here is an over engineered bash script to download all their episodes:

wget http://www.bbc.co.uk/podcasts/series/timc/all/ ; cat index.html | grep -Po "timc\_[0-9]*\-[0-9]*[a-z]\.mp3" | sed "s/^/wget http\:\/\/downloads.bbc.co.uk\/podcasts\/radio4\/timc\//g" | sh ; yes | rm index.html

Download and enjoy!

Thanks for Reading

Thursday, 2 June 2011

Kill all my processes! muhahaha!

Hi all,

This is an interesting command line a friend of mine wrote, I'm posting it here because its handy for killing database processes that are spinning and you can't sort it out nicely:

ps -ef |grep [someprocesseswiththesamename]|grep -Po "^\w+\s+\d+"| grep -Po "\d+"| sed "s/^/|kill -9 /" |sh

Say you have 50 apache2 services and apache is playing up so you want to kill all of them. (An example only...). You would do this:

ps -ef| grep apache2 |grep -Po "^\w+\s+\d+"|grep -Po "\d+"|sed "s/^/kill -9 /"|sh

Quick description:

ps -ef : List processes

grep apache2: Chops down the ps -ef to only show lines with apache2 in

grep -Po "^\w+\s+\d+" : Display just the name and PID

grep -Po "\d+" :Display just the PID

sed "s/^/kill -9 /" :build the command line, replaces the beginning of line char with "kill -9" the PID from the previous line gets appended.

sh: Pipe all that lot to the shell

Thanks for reading,

Trev