Tech Tips
I use this simple script when troubleshooting network problems on machines when I can't see the screen—for example, when I'm under a desk, wiggling Ethernet cables to find a bad one. When I hear the pings, I know it's fixed. Or, you can use this to drive your coworkers nuts by running it on their machines and sending single pings at random times during the day (or perhaps substitute moo for ping).
I made this into a script because I can't remember that big long line, and I would hate to type it in a lot. Here's sonar.sh:
#!/bin/bash # # Written by Mike Studer a long time ago # Make sure you obtain a nice submarine ping sound. # ie., ping with an echo (sonar.au used here) /usr/sbin/icmpinfo -vv | \ /usr/bin/nawk '$4 == "ICMP_Echo" {print $0; system("/usr/bin/aplay -q ~/sounds/sonar.au")}'
You need to install icmpinfo and aplay to use this.
Usage: Run this on the machine on which you want to make noise (test):
sudo sonar.sh
Run this on a machine that is trying to get to the test machine for a nonstop ping barrage:
ping {testmachine}
For a single ping, run this:
ping -c 1 {testmachine}
—Mike Studer
In addition to viewing text, the less command can be used for viewing nontext files. This is done by using less' ability to invoke a preprocessor for input files. These preprocessors then can change the way the file's contents are displayed. For example, suppose you had a script lesspipe.sh:
#! /bin/sh case "$1" in *.tar.gz) tar -tzvf $1 2>/dev/null ;; esac
Make sure the script is executable, and set the LESSOPEN environment variable to:
LESSOPEN='|/path/to/lesspipe.sh %s'
Now you can use less to view the contents of .tar.gz files:
$ less autocorrect.tar.gz -rwxrwxrwx raogr/raogr 84149 2009-02-02 03:20 autocorrect.dat -rwxrwxrwx raogr/raogr 443 2009-02-02 03:21 generator.rb -rwxrwxrwx raogr/raogr 181712 2009-02-02 03:21 autocorrect.vim
More-sophisticated versions of lesspipe.sh are available. You already may have a version installed, or you may have the lessopen.sh script installed. If not, search the Internet for lesspipe.sh. With the more-sophisticated versions, you can do things like this:
$ less knoppix_5.1.1.iso CD-ROM is in ISO 9660 format System id: LINUX Volume id: KNOPPIX Volume set id: Publisher id: KNOPPER.NET ... /KNOPPIX /autorun.bat /autorun.inf /autorun.pif /boot /cdrom.ico /index.html /KNOPPIX/KNOPPIX /KNOPPIX/KNOPPIX-FAQ-EN.txt
—Gururaj Rao
I work all the time with a laptop, and as you all know, from time to time laptops can get hot. When you're actually using it as a “lap”-top, or when you're close enough to hear the fans, you know when it's heating up. But, when the conditions are such that you don't realize it's heating up, your laptop can get pretty hot. And, you've all heard the stories about laptops catching fire.
The following script monitors the temperature and slows down your system when it gets too hot. The script should be run as root from cron every minute or so. You need to install cpufrequtils to get it to work:
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin: # Get the temp of the core 0 core_O=`acpi -t | awk {'print $4'} | head -n 1` # Get the temp of the core 1 core_1=`acpi -t | awk {'print $4'} | tail -n 1` # Round the result of core_O convert_O=$(echo "scale=0; $core_O/1.0" | bc) # Round the result of core_1 convert_1=$(echo "scale=0; $core_1/1.0" | bc) # Set maximum permissible temperature. max=90 # Set temperature at which the CPU frequency can # be increased again (if needed). min=68 if (( $convert_O >= $max )) ; then # Too hot, slow down to 800MHz. cpufreq-set -f 800 echo "CPU temp higher than desired!!!" | \ mail -s "CPU temp too high, set frequency to half" root elif (($convert_O <= $min)) ; then # Cooled down, allow frequency to increase again if needed. cpufreq-set -g ondemand fi
As you can see, in the script, I actually use the temperature only of core 0, because I know that this core tends to overheat before core 1.
—Alberto