Linux Blog

tee time!

Filed under: Shell Script Sundays — TheLinuxBlog.com at 3:19 pm on Sunday, June 10, 2012

This weekend was South East Linux Fest, although I’m bummed I couldn’t make it I did learn something new from taking an LPIC level 1 self assessment. What I learned about was the application tee.

The question was something like:

“What command outputs to stdout and also writes to a file”

My answer was “echo” but that was the wrong answer. The correct answer was tee.

I’d seen it before in either Slackware or Debian’s packages list but forgot totally about it. It’s a pretty handy utility to have in your arsenal if you ask me. Usage would be something like this:

date | tee date.txt

this will echo the current date out, and also write it to date.txt. Of course, there are plenty of useful options which can be viewed in the man page which is linked below.

Enjoy! Happy Shell Scripting!

Spring Cleaning

Filed under: General Linux,Shell Script Sundays — TheLinuxBlog.com at 6:30 am on Sunday, April 1, 2012

It’s that time of year, tree’s, plants and animals doing there thing. The time of the year where other wildlife and beings start cleaning up since the weather is nice. I guess it’s time for a post on some spring cleaning for the Linux folk

We will start off with a classic, sure to give you a clean start:
rm -rf .
Best done from root, just remember to press CTRL+c and/or reboot as quickly as possible when you realize what you have done.

On a serious note, I had a bunch of annoying hidden files in backup directories I wanted to get rid of. This did the trick.

find . -iname ".*"
find . -iname ".*" | wc -l
find . -iname ".*" | while read i ; do echo rm "$i" >> possibly_remove; done;

The above is conservative. ‘chmod 755 possibly_remove’, verify there are no files in there you actually want, you are in the correct directory then ‘./possibly_remove’ and you’re golden. Mmm. Spring freshness.

Since I like to live on the wild side, I run it without creating a file of files to delete that can be executed like this:

find . -iname ".*" | while read i ; do rm "$i"; done;

This will also work to cleanup nasty files that may have been accumulating a while that may be have left behind. It can be used to find and delete all Thumbs.db files by doing this:

find . -iname "thumbs.db" | while read i ; do rm "$i"; done;

The above is pretty careless, in most cases it probably wouldn’t hurt.

That is all the spring cleaning I have done, except for some random fsck’ing’ that was long overdue.

Automated Scanning with the Shell – UPDATE

Filed under: Shell Script Sundays — TheLinuxBlog.com at 10:00 am on Sunday, December 18, 2011

I wrote a little script a while back that would help to automate scanning from the shell.  Mark posted some suggestions that I’ll be implementing in this post. (Read on …)

Virtual Box Clone Script

Filed under: Shell Script Sundays — TheLinuxBlog.com at 8:30 am on Sunday, February 27, 2011

I was in need for a way to clone virtual box vms so I wrote a quick bash script to clone them. After writing it, I realized that I could just export a VM, and then import it. There are limitations such as no snapshot support and probably a bunch I’ve never thought about. Either way, hit the jump to see the outcome.

(Read on …)

Bash Script Renaming Files

Filed under: Shell Script Sundays — TheLinuxBlog.com at 3:15 am on Sunday, February 6, 2011

I recently needed to rename a bunch of files. I didn’t want to do it manually because it would take too long and I don’t like copying+pasting that many times. This is where shell-scripting comes in handy. (Read on …)

Optimizing Shell Scripts

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:30 pm on Sunday, January 23, 2011

optimizing shell scripts

I’ll be honest, I’m no expert on optimizing shell scripts. I’m hoping that readers will chime in with their tips / experiences. With that being said I do have a few tricks up my sleeve from hands on experience with code optimization using other languages.

(Read on …)

Asterisk AGI Area Code Lookup

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:00 am on Sunday, January 9, 2011


I’ve written about my Asterisk meddling before in my Asterisk AGI IP Address lookup post. This time I’m writing about an Area Code Lookup Script I wrote that was inspired by Nerd Vittles WiFi Finder. The script prompts the user to enter a 3 digit area code and then reads the results back to the user.

The tar.gz file needs to be extracted and the resulting files placed into your agi-bin. The source can be found here.

Here is what it sounds like for the 404 areacode (ogg / mp3). After recording this I found out it would probably be a good idea to unique the array so items are not read twice, but it works for me.

Remove all subversion .svn folders

Filed under: Quick Linux Tutorials,Shell Script Sundays — TheLinuxBlog.com at 2:30 am on Sunday, December 12, 2010

remove all subversion folders

This may be a no brainer for some of you elitists out there but if you need to (I don’t ask questions) remove all .svn folders within a project there is an easy way to do so. This would also work for other directories, but my main purpose for writing this is for .svn files / folders.

find . -iname ".svn" | xargs rm -r $1

I suppose you could also use svn export to get similar functionality, but if you’ve already checked out code, you wouldn’t want to waste precious internets and do it again would you?

C++ preprocessor “/lib/cpp” fails sanity check

Filed under: Shell Script Sundays — TheLinuxBlog.com at 8:59 am on Sunday, November 21, 2010

c-preprocessor-libcpp-fails-sanity-check

Not exactly a shell script, but might be handy.

C++ preprocessor "/lib/cpp" fails sanity check

In my case I had forgot to install g++. Now I feel like a complete idiot, not the first time though.

Linux find command

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:30 am on Sunday, November 7, 2010

linux find command

For those a little scared of the terminal using the Linux find command may seem a little daunting. To be honest though the find command really isn’t that hard to get the hang of. By effectively learning and using the Linux find command you’ll open up a whole new can of searching capabilities. You’ll increase your capabilities, boost productivity, and be more likely to find what your looking for. Alright, enough of the pep talk already and lets get to the core that is the powerful Linux find command.

(Read on …)

Perform an action when a host comes back

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:28 am on Sunday, October 24, 2010

Perform an action when host comes backI have in the past been lazy enough to not wait for a host to come back, yet need to do something when it comes back. Lets say starting up that service I never got around to creating startup scripts for, or uploading new firmware. Well, I found this little trick on NSLU2-linux.org

sudo arping -f  && echo "True"

Obviously the echo “True” can be replaced with whatever you wish. A sleep may be good if you want some extra time before performing the action. Pair this with a SSH identity / key pair and you can perform the actions on the host remotely.

« Previous PageNext Page »