Archive for Linux
How to determine DST time changes
Posted by: | CommentsHere’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
Posted by: | CommentsI 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
Posted by: | CommentsHere’s another logging routine, this one is written in Bourne shell:
#!/bin/sh 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
Posted by: | CommentsHere’s how to find out your external IP address courtesy of this hint:
http://www.macosxhints.com/article.php?story=20060602180942480
curl --silent http://checkip.dyndns.org | 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 192.168.63.1 ipAdEntAddr IpAddress \
| grep -E -v '(127.0.0|169.254|192.168.63.1)' \
| cut -d : -f 2 | sed 's/ //g'
Line Terminations
Posted by: | CommentsLine terminations for different operating systems:
| unix | 0×0a | LF |
| Classic Mac | 0×0d | CR |
| Windows | 0×0d 0×0a | CR LF |
To convert a text file with DOS line termination to UNIX line termination:
tr -d '\015' < winfile.txt > unixfile.txt
or
sed s/.$// winfile.txt > unixfile.txt
To convert a unix file to a DOS file:
sed s/$/\x0d/ unixfile.txt > winfile.txt
Run as root only
Posted by: | CommentsTo make sure that a script will be run by root only:
#!/bin/sh if [ `id -u` != 0 ]; then echo "Permission denied, must be root" exit fi # Do the thing...
Authenticate Users
Posted by: | CommentsThis snippet could authenticate users using their /etc/passwd or /etc/shadow entry. May have to run this with higher than normal privilege:
#!/usr/bin/env perl print "Username: "; chomp($uname = <stdin>); $pwd = (getpwnam($uname))[1]; # get the user's pwd die "invalid user\n" unless defined $pwd and length $pwd; $salt = substr($pwd, 0, 2); system "stty -echo"; print "Password: "; chomp($word = <stdin>); print "\n"; system "stty echo"; if (crypt($word, $salt) ne $pwd) { die "Sorry...\n"; } else { print "ok\n"; }
How to Burn CDs
Posted by: | CommentsFor accomplishing other tasks such as copying CDs, etc., try carefully reading the cdrecord manual page and, if necessary, consulting the canonical CD recording FAQ at http://www.cdrfaq.org/.
——————————————————
Creating a data CD:
Step 1: Make a directory to contain the files you want to place on the the CD. “mkdir /image/userdir/” is the standard method.
Step 2: Copy the files from wherever they are to the directory you just created.
Step 3: Create the ISO9660 image that will be burned on the CD. You do this using the mkisofs command. An example command is:
csh> cd /image/userdir/ csh> mkisofs -o /image/burn-image/.iso -l -R -L -V "" -P "" -p "" -A "" . -o: the name of the file that will contain the image -l: use long file names -R: use Rock Ridge extensions. This means that long filenames will be used, file uid/gids and permissions will be preserved, symbolic links will be included, etc. In other words, the CD will try hard to emulate a Unix file system. [-r: This is like the -R option, but file uid/gid are set to 0, files will be readable by anyone and all write permissions will be removed. Use this switch if you anticipate needing to read the CD in an environment where your uid/gid do not exist. E.g., if you are sending to CD to another institution.] -L: Allow file names beginning with '.'. -V, -P, -p, -A: See the mkisofs man page. The final argument (in the example '.') is the name of the top-level directory containing file data. See the mkisofs manual page for further details.
Disable single user mode using lilo
Posted by: | CommentsIn your LILO configuration section, write something like:
image = /vmlinuz label = Linux root = /dev/hda1 password = wingedlizard restricted read-only
Then chmod this file 600 (so nobody but root can read it) and re-run /sbin/lilo.
The “restricted” keyword means that LILO will stop and ask for a password if you try to boot this kernel with _any_ keywords such as “1″ or “single” or “init=/bin/bash”. A password won’t be required during normal (no-added-keywords) boots.
Determine Disk Usage
Posted by: | CommentsThis command will show the number of KBs used for all non-hidden files and folders in the current directory:
du -sk * | sort -rn