Author

The Archives

  • 06.25.09
    Samba available shares shell | pfortuny | (0)
    $ smbclient -L //melchor -U username Shows all the available shares at melchor. Asks for a password if needed. The -U option may be unnecessary if shares are browseable. The snippet is useful if you have forgotten a share name, for instance.
  • 04.13.09
    OpenBSD’s pf null pointer dereference network, news, security | pfortuny | (0)
    We have talked quite a few times about pf, OpenBSD's Packet Filter (firewall). Well, a bug has been discovered which may trigger a kernel panic. There exists a solution, be sure to patch your boxes asap. Notice that the 'editing' solution works on all platforms and versions (at least from 4.2 upwards and probably on older ones).
  • 03.24.09
    gnuplot just for coordinates shell | pfortuny | (2)
    I needed a list of coordinates urgently, and I needed it in a text file (I am using LaTeX a lot lately). Gnuplot does the job properly, if told to do so: $ gnuplot gnuplot> set terminal table gnuplot> set output "hyperbola" gnuplot> set parametric gnuplot> plot [t=-1.5:1.5] cosh(t),sinh(t) gnuplot> quit $ cat hiberbola |awk '/[0-9]/{print "(",$1,",",$2,")"}' > hyperbola.txt The above saves in "hyperbola" a list of coordinates: each line contains a pair x y i (x coordinate, y coordinate, type of coordinate). The awk line turns it into a list of parenthesized coordinate pairs. The lines above saved me a lot of troubles yesterday.
  • 03.12.09
    nohup: put your computer to work and leave cmd, scripts | pfortuny | (0)
    $ nohup R -q -f batch & That was how I made my Department's computer run a lot of computations in R from a remote shell, while being able to log out without killing the process (it runs on even if you log out). You might redirect the output somewhere (it gets saved in a file called nohup.out by default). Nohup stands for "Do not comply with HUP signals".
  • 03.06.09
    Accents everywhere (to be removed, obviously) scripts, shell | pfortuny | (2)
    Accents have again (I still live in Spain and do some work for the Spanish Administration) crept into my terminal. This time it was a group of University professors which had to create a lot of files and directories concerning a historical catalog and even though I remember telling the coordinator not to use accents or spaces or any funny characters, they did it. I should have known better... The problem was then to take away all spaces and non-ASCII characters from directory and file names. After thinking about it a bit, I came up with the solution below. There may be ...
  • 02.28.09
    Using $|=1 in real life, for squidGuard shell | pfortuny | (0)
    In 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.22.09
    Perl directory traversal scripts | pfortuny | (0)
    The 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.16.09
    Perl for accents and spaces in html hrefs automated, scripts, shell | pfortuny | (0)
    Despite 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.10.09
    Some xargs scripts, shell | pfortuny | (0)
    Rafacas 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 ...
  • 02.04.09
    Batch convert RTF to PDF automated, scripts, shell | pfortuny | (0)
    You've got the full details here (the OpenOffice Forum site). After following the instructions there, I was able to convert a bunch of some 500 rtf files into pdf's with the following single 'line of code' (although there must be a newline after the first quote ') $ find /Users/pedrofortunyayuso/Desktop/fichitas -name "*rtf" | while read -r i ; do /Applications/NeoOffice.app/Contents/MacOS/soffice -invisible "macro:///Standard.MyConversions.SaveASPDF($i)" ; done All the above shows my computer as an evident OS X, but this works on Windows (the referred site does the job on Windows, using, obviously a different shell construct) and, as far as I know, on ...