Some of my systems are logging this error:
su: pam_env(su:session): Unable to open env file: /etc/default/locale: No such file or directory
I already had the “locales” package installed, to create the file:
dpkg-reconfigure locales
Follow the prompts to choose your locale(s). Result:
cat /etc/default/locale
# File generated by update-locale LANG=en_US.UTF-8
This is similar to my little shell one liner to verify tar archives. Exit status of 0 means the archive is good, anything else means there’s a problem. Most of the problem archives I encountered had a status of 2, but a few 3’s and 9’s as well — see “man unzip” for explanation of status codes. Using a while loop because some of the archive files names have spaces in them, which trips up the for loop:
find . -name "*.zip" | while read f; do unzip -t "$f" &> /dev/null; err="$?"; echo checking "$f"; echo $err "$f" >> zip-check.list; done
The goal is to download pdf files from http://example.com/dir1/dir2/, where dir1 name is constant, but dir2 is a number between 100 and 499 (e.g. http://example.com/dir1/309/file258.pdf).
First, I’ll say that wget is a powerful tool and can place a burden on the site we’re grabbing data from (and probably get us banned as we’ll be perceived as carrying out a DOS attack). To avoid this, the example below will use a 5 second wait between downloads so as to not trouble the web server too much and keep the site usable for others.
Was trying to figure out how to insert line numbers into a huge file with sed or awk, then stumbled across “nl”, a sweet little baby that comes with GNU coreutils and numbering files is what it does for a living. GNU coreutils is full of gems!
Boring:
ak@gd:~$ cat file blah blah blah bleh blah
Awesome:
ak@gd:~$ cat file | nl -n ln -w1 -s\| 1|blah 2|blah blah 3|bleh blah
I’ve got a script that loops through a list of directory names and compresses them. There are lots and once in a while I want to check on the progress and find out which directory in the list it’s working on.
The name of the script is compress.sh, tar will run as a child of it, which I can locate using the parent PID:
me@my:~$ show.proc.sh compress.sh USER TT PID PPID %CPU %MEM VSZ STARTED TIME COMMAND me pts/19 1810 24357 0.0 0.0 4496 10:15:37 00:00:00 | \_ /bin/bash ./compress.sh me pts/19 1857 1810 0.5 0.0 3696 10:16:03 00:00:01 | | \_ tar cfj 833444.tar.bz2 833444
show.proc.sh:
1 2 3 4 5 6 7 | #!/bin/bash # get pid pid=$(pgrep $1) ps axfo user,tty,pid,ppid,pcpu,pmem,vsz,start,time,args | head -1 ps axfo user,tty,pid,ppid,pcpu,pmem,vsz,start,time,args | grep $pid | grep -v grep |
compress.sh:
1 2 3 | #!/bin/bash for d in $(cat dir.list.2010-05-11); do tar cfj $d.tar.bz2 $d && rm -rf $d; done |
BASH script to enumerate titles and chapters of a dvd and rip each into a separate avi using mencoder. DVD device can be a path to mounted iso (e.g. /mnt/iso/) or a real device (e.g. /media/cdrom0/).
To rip just the longest title, try this.
After a clean install of Ubuntu Karmic (9.10), on a box with an Nvidia card (1), went into “System” > “Administration” > “NVIDIA X server settings” and changed configuration to TwinView (I’m using dual monitors), which worked, but saving the configuration returned:
Failed to parse existing X config file '/etc/X11/xorg.conf'
Nothing further found in the logs. The solution was two-fold.
Here’s a simple solution to run multiple instances of Firefox, each with own user profile (and thus cookies, extensions and themes), all running as separate processes. Useful for troubleshooting and to keep one misbehaving site from crashing all your firefox windows (I’m guilty of running way too many at once).
Got thousands of tar archives being transferred from various machines to one repository. Found that some of the archives are bad, either because the network transfer didn’t complete or the archive process was interrupted on the machine that created the archive (due to insufficient disk space, etc). Whatever the cause, needed a method to verify the archive integrity.
Tar provides options for verify the archive integrity by comparing it with the file system. In this case, I needed the ability to verify the archive without access to the original file system.
The BASH one liner below will find all archives below current directory, loop through each one attempting to list its contents, discard the archive content list, capture and log the tar command’s exit status along with archive name and redirect both to a log. Exit status of 0 means the archive is good, 2 means it’s bad (haven’t seen a 1). Redirecting output to /dev/null while capturing exit status turned out trickier than I thought, but this seems to work well:
1 | for f in $(find . -name "*tar.bz2"); do tar tfj $f &> /dev/null; err="$?"; echo $err $f >> tar-check.list; done |
The split command is one gem of a Giant Dork tool, but it expects to be given the number of lines to split a file along. It’s easy enough to fire up a calculator to do this, but sometimes a programmatic method is desirable. Here’s a bashism that’ll do it:
1 | split -l $(echo $(( $(cat sourcefile | wc -l) / 3))) sourcefile sourcefile. |