Browsing TagLinux

How to determine DST time changes

Here’s how to determine the dates when the Daylight Savings Time changes for a given year (I keep forgetting how to do this.):

zdump -v /etc/localtime|grep 2008 /etc/localtime Sun Mar 9 06:59:59 2008 UTC = Sun Mar 9 01:59:59 2008 EST isdst=0 gmtoff=-18000 /etc/localtime Sun Mar 9 07:00:00 2008 UTC = Sun Mar 9 03:00:00 2008 EDT isdst=1 gmtoff=-14400 /etc/localtime Sun Nov 2 05:59:59 2008 UTC = Sun Nov 2 01:59:59 2008 EDT isdst=1 gmtoff=-14400 /etc/localtime Sun Nov 2 06:00:00 2008 UTC = Sun Nov 2 01:00:00 2008 EST isdst=0 gmtoff=-18000


Obviously, change 2008 to whatever year you want.

Find Out the Top 10 CPU Hogs

I found this command useful in finding out which top 10 processes are hogging my CPU resources. Note that this command is specific to the Red Hat flavor of Linux. See the man page for ps for the correct output format to use for your specific platform:

ps -eo pcpu,pid,user,args | sort -k1 -r | head -11

Substitue pcpu above with pmem to see the memory hogs instead.

Bourne Shell Logging Routine

Here’s another logging routine, this one is written in Bourne shell:


log_message() {
    echo `date "+%m/%d/%y %H:%M:%S %Z"` "$1" | tee -a aaa.out

log_message "Hello there"
log_message "Goodbye"

Sample output:

08/28/07 23:16:13 EDT Hello there
08/28/07 23:16:13 EDT Goodbye


Determining the External IP Address

Here’s how to find out your external IP address courtesy of this hint:

curl --silent
    | awk '{print $6}' | cut -f 1 -d "<"

If you are using Apple’s Airport Extreme Basestation (mine is particularly the Time Capsule and this is where I have tested this), and you have the SNMP interface enabled, you can run the following command

prompt$ snmpwalk -Os -c public -v 1 ipAdEntAddr IpAddress 
    | grep -E -v '(127.0.0|169.254|' 
    | cut -d : -f 2 | sed 's/ //g'

Line Terminations

Line terminations for different operating systems:

unix 0x0a LF
Classic Mac 0x0d CR
Windows 0x0d 0x0a CR LF

To convert a text file with DOS line termination to UNIX line termination:

tr -d '15'  unixfile.txt


sed s/.$// winfile.txt > unixfile.txt

To convert a unix file to a DOS file:

sed s/$/x0d/ unixfile.txt > winfile.txt