Archives for June, 2010

30
Jun

A Great Countdown Script Example

Somebody over at the linuxconfig.org website posted a really good countdown script that I’d like to share with you. Specify a date and time and the script will start and display the countdown. Take a look here:
http://www.linuxconfig.org/time-countdown-bash-script-example

29
Jun

Check For Empty Directories Using ‘find’ Shell Command

find /path/to/directory -type d -empty -exec echo {} ;

I think it’s easy to get the idea based on the example above, but just in case you need inspiration, you could automatically remove these empty directories with the following (Careful! This uses ‘-rf’ flag which shows no warnings or mercy!):

find /path/to/directory -type d -empty -exec rm -rf {} ;

Check out some additional methods here:

http://www.cyberciti.biz/faq/linux-unix-shell-check-if-directory-empty/

28
Jun

Taking it Easy on Monday with Technobabble

I ran across this video the other day and wanted to share with everyone. Think of it as a light way to start off your week without having to think. Enjoy!
YouTube Preview Image

25
Jun

How To: Add a “Press Any Key to Continue” Message to a Script

Adding a “Press any key to continue” message to a script is actually quite easy because it’s already built into the read command. Here’s a couple examples of how to use it:

#!/bin/sh

echo "A First Method"
read -s -n 1 -p "Press any key to continue..."

# insert echo here for cleaner output
echo

echo "A Second Method"
echo "Press any key to continue..."
read -s -n 1 any_key
echo "Now exiting"
exit 0

Note: “any_key” was simply a made up name. It can be anything. As always, be sure to take a look at the man page for more information!

24
Jun

The Most Dangerous Linux Command

James over at http://dazzle.cs.mcgill.ca has come across a humorous, and frightening, Linux command. It’s been dubbed “The Most Dangerous Command”. Take a look! It makes rm -rf / seem like a PG rated horror film…
http://dazzle.cs.mcgill.ca/wordpress/?p=36

23
Jun

Calculating /proc/cpuinfo BogoMIPS After Kernel Init

Upon starting up your Linux kernel, a bogoMIPS calculation will be made and recorded into /proc/cpuinfo. This is a value that is not dynamically updated, so if you change the clock speed of the CPU, the bogoMIPS value contained in /proc/cpuinfo will not be updated. If all you’re interested in is a simple verification that your CPU speed was changed, you could compile and run the following bogoMIPS calculation program both before and after the clock speed change.

http://www.ibiblio.org/pub/linux/system/status/bogo-1.2.tar.gz

Simply call ‘make’ to compile the program. You may need to modify the Makefile in accordance to your needs (cross compiling, gcc flags, etc). You may notice that the bogoMIPS value calculated by this program is not the same as the value calculated by the kernel. That’s okay. What matters here is that you can verify a change in CPU speed. After all, “bogo” stands for “bogus” which simply means “fake”.

Source:
http://tldp.org/HOWTO/BogoMips/bogo-faq.html

21
Jun

Prevent Time-Based ‘fsck’ Checks on Root Partition with ‘tune2fs’

In an embedded system without a battery backed real time clock (RTC), a time-based ‘fsck’ check can be quite annoying. To disable the time-based check, use the tune2fs command on the drive containing the root partition like so:

tune2fs -i 0 /dev/<device node>

There’s more information here at this link for those of you interested:
http://serverfault.com/questions/28343/will-my-system-fsck-when-i-reboot

16
Jun

Minimize Linux Serial Port Latency

When using Linux serial ports, the tty has a default 5 to 10ms latency time built-in. To drop this, use the low_latency parameter of setserial. This is useful for getting a more real-time response in Linux serial ports. Be sure to check out the man pages for more information.

Minimize the receive latency of the serial device at the cost of greater CPU utilization. (Normally there is an average of 5-10ms latency before characters are handed off to the line discpline to minimize overhead.) This is off by default, but certain real-time applications may find this useful.

11
Jun

Run Shell Script Subroutines in Terminal with Source Command

If you run a set of commands frequently, you might want to think about creating a sourced shell script with subroutines. For example, maybe you like to see the current date, a calendar, and a quick fortune (with the fortune package installed). Instead of typing cal and then date and then /usr/games/fortune -s manually each time, simply include it in a shell script that contains a subroutine that will do it all for you. All you need to do is create the script and subroutines and then source it like this:

. /my.subr

Notice the space between the period [.] and the script name. I usually use the .subr extension on my sourced scripts to tell them apart, but you can use whatever filename you want (it doesn’t even have to have an extension).

Then, simply call your subroutine within your shell script. Continuing with the example scenario described above, here is the shell script called my.subr that was sourced…

startmyday(){
   cal
   date
   echo
   /usr/games/fortune -s
}

anotherfunction(){
   echo "put whatever you want in this function call"
   echo "this is just a filler."
}

yetanotherfunction(){
   echo "put whatever you want in this function call"
   echo "this is yet another filler."
}

This is showing the sourced shell script subroutines in action…

# startday
     June 2010
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30         

Fri Jun 11 04:17:56 UTC 2010

Do not drink coffee in early A.M.  It will keep you awake until noon.
# anotherfunction
put whatever you want in this function call
this is just a filler.
# yetanotherfunction
put whatever you want in this function call
this is yet another filler.
#
10
Jun

Tips for Navigating Directories in Linux

Here are some basic Linux commands that will allow you to navigate easier within the terminal. These commands include dirs, pushd, popd, and cd.

cd
This is probably one of the most known commands since you really can’t get around a Linux terminal without it. There are some pretty neat tricks you can use to more quickly navigate directories. These include:

In order to talk about the next commands, you need to understand what a stack is. Imagine a spring-loaded plate holder like the ones you’d find at an all you can eat buffet (this is dirs). The employees fill this plate holder by pushing a plate onto the plate holder. Then another plate is pushed onto the top of that plate (this is pushd). This is repeated again and again and then soon, you have a full stack of plates. In order to get to any of the plates in the middle, you must pull the plate on top off, and then the next, and then the next until you get to the plate you want (this is popd). This can continue until the stack is empty. This example is known as a Last In First Out (LIFO) or First In Last Out (FILO) data structure and that’s exactly what we’re dealing with here.

Now that you have an understanding of what a stack is, let’s chat about the next three commands: dirs, pushd, popd.

dirs
This is the command you use to display the stack of currently remembered directories.

pushd
This command will push a given directory to the top of the stack of remembered directories.

popd
This command will pull the top directory off the stack of remembered directories.

Next Page »