February 2009
The Archives
-
02.28.09Using $|=1 in real life, for squidGuardIn a previous minipost I mentioned Perl's $|=1 'autoflush output' option, which autoflushes all output. This is relevant in IPC more than in interactive scripts (these are USUALLY autoflushed, although any threaded program will show you differently). In the Squid configuration at a local firewall where authpf is used, the system does not only filter connections per-user (which is authpf's job), but it also authenticates them to squid via authpf. The relevant configuration lines in /etc/squid/squid.conf are: # next line needed to read the /var/authpf directory cache_effective_group authpf external_acl_type check_authpf children=15 %SRC /usr/local/bin/authpf.pl acl authpf external check_authpf They tell Squid to get the IP's (%SRC) ...
-
02.25.09Bash 4.0 releasedVia Slashdot I found out about bash version 4.0 being out. Bash is the GNU Project's Bourne Again SHell, a complete implementation of the POSIX.2 shell spec, but also with interactive command line editing, job control on architectures that support it, csh-like features such as history substitution and brace expansion, and a slew of other features. The new version fixes several bugs in the 3.x releases and introduces a bunch of new features. The most notable ones are associative arrays, improvements to the programmable completion functionality, case-modifying word expansions, co-processes, support for the `**' special glob pattern, and additions to the shell ...
-
02.24.09Adding software in FreeBSDThe easiest way is to add a binary package with: % pkg_add <package> Packages in FreeBSD are .tbz files with some special meta-files (or files with meta information) inside it. However you will use pkg_add in this fashion most likely: % pkg_add -r <package> This connects to the repository matching your release, downloads the package (and all its dependencies) and installs the package. Another example of how easy FreeBSD can be ;)
-
02.22.09Perl directory traversalThe following chunk of code sub traverse { my ($dir, $callback) = @_; my $present; opendir $present, $dir or return(); for (grep { ! /^(\.|\.\.)$/ } readdir $present) { my $path = "$dir/$_"; &$callback($path); traverse($path, $callback) if -d $path; } closedir $present; return(); } is an easy implementation (without error-checking) of a generic directory-traversing function in Perl. It should be called traverse(dir, ...
-
02.20.09Displaying last lines of a file in real time$ tail -f /var/log/messages Displays continously (in "real time") the last lines of /var/log/messages as it grows.
-
02.18.09AliasThis command, when invoked without arguments, shows the list of aliases in your shell session: $>alias alias dir='ls -l' alias l='ls -alF' alias md='mkdir -p' It also allows you to create your own aliases: $>alias lc='ls --color' If for some reason, you want to delete an alias, you can use the unalias command: $>unalias lc Aliases can help you saving a lot of time by avoiding repetitive and long commands and options. If you want them to be permanent, you should add those definitions to your .bashrc file.
-
02.16.09Perl for accents and spaces in html hrefsDespite the title looking like spam, it uses all the relevant keywords in a problem which I guess is more common than it looks like, especially in non-English speaking countries. I had created (automatically, not by hand) a set of html, pdf and rtf files of the 477 items of a regional catalogue of industrial estate (sorry, no references because it belongs to other people and they have not published it yet). Then I made the index.html page listing and linking to all those files. It looked like a list of lines like the following one (notice that what follows looks ...
-
02.14.09Is your site up?When I cannot reach one of my sites, I do not know if it is my problem, my ISP's or my hosting provider's. This is why I use the service down for everyone or just me. I have written a simple script which uses that service. Its usage is: $ ./is_up.sh commandliners.com commandliners.com is up and the script is: #!/bin/bash # is_up.sh # 2009 - Rafa Casado - rafacas@commandliners.com numargs=$# if [ $numargs -ne 1 ] then echo "Usage: $0 domain" echo "Ex: $0 commandliners.com" exit 1 fi DOMAIN=$1 IS_UP=`wget -nv -O ...
-
02.12.09Fix package database% pkgdb -F In FreeBSD, interactively fixes the package database. Useful after an upgrade.
-
02.10.09Some xargsRafacas has already mentioned it, but xargs is sometimes much more useful than what it looks like. Two examples come to mind: Way too many files for rm or ls. It may well happen that a script has generated more than 10000 files in the same directory (it was your friend, not you, I know). If you try and rm * in there, you will be in trouble. Ditto if you simply want to count them with ls | wc -l. However, the following works: $ find . -type f -print0 | xargs -0 ls | wc -l (or rm instead of ...