Author

The Archives

  • 02.10.09
    Some xargs scripts, shell | pfortuny | (1)
    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 ...
  • 01.29.09
    sdf, public Unix shell access shell | pfortuny | (5)
    I have mentioned it several times before, but I have been told it deserves an entry on its own. The Super Dimension Fortress (known also as freeshell) is a public Unix system: that is a Unix system (actually Netbsd running on an Alpha-64) to which everyone (each person in the world having a network connection) can log in and which anyone can use. From its main page: Our mission is to provide remotely accessible computing facilities for the advancement of public education, cultural enrichment, scientific research and recreation. Members can interact electronically with each other regardless of their location using passive or interactive forums. Further purposes include ...
  • 01.23.09
    Space for shell | pfortuny | (5)
    So your friend sent you a batch of tiffs to be converted into jpg's (using ImageMagick's convert command). However your friend (who is not so geeky as you) uses spaces in filenames (which is a deadly sin), like in First photo of birthday.tiff Second photo.tiff You wanted to use a shell for loop, but the obvious $ for i in `find . -name *tiff` ; do convert "$i" "${i%tiff}jpg" ; done produces garbage (try it). This is just one of the consequences of your friend's carelessness. But there is a solution. IFS (Internal Field Separator) is a shell variable controlling what character(s) delimit a 'field' in ...
  • 01.21.09
    Perl autoflush cmd, shell | pfortuny | (0)
    $ perl -e '$|=1; while(<>){print "you entered: $_";}' Even though in the above code it is irrelevant, the $|=1 assignment makes all the output be unbuffered (auto-flushed). This is quite useful in sockets, network protocols and IPC.
  • 01.15.09
    Where is an executable? cmd, shell | pfortuny | (0)
    # which cat /bin/cat The which command shows the first instance of an executable file with the specified name found following your $PATH variable.
  • 01.09.09
    Authpf: authenticated routing and firewalling on OpenBSD network, security, shell | pfortuny | (0)
    In our detailed description of OpenBSD's packet filter (here and there) we mentioned authpf, and spoke of it as a useful tool, but what is it use? I tend to understand it as an instrument for authenticated routing, that is, a way to provide routing (and firewalling etc...) services only to authenticated users. Think of a corporate setting with different users having access to different services according to their identities (and not according to their computer's IPs, which may well be dynamic or different). For example, user boss may access the firm's MAIN smb (ports 139, 435) server and any http ...
  • 01.03.09
    Script: all your keystrokes are belong to us cmd, shell | pfortuny | (0)
    $ script -a filename All the input and output (on stdout) is typescript to filename, probably for later inspection or for printing (with lpr, for which the file is prepared). Might be useful for forensic purposes (to know what you broke after an incident and what you did not break).
  • 12.30.08
    rsync with ssh-rsa+authorized_keys security, shell | pfortuny | (0)
    Much like explained in a previous post, one can use a passwordless RSA key to set up a cron job doing an rsync of one's computer on a remote server, via ssh. The relevant part of the authorized_keys file is (everything in the same line): command="rsync --server -vlogDtpr . /home/pfortuny/backup/",no-port-forwarding, no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa ..... Taking into account that the -vlogDtpr depends on the specific options of the rsync command you issue. In my case, the script is simply (right now) $ cat ./bin/backup.sh #!/bin/sh cd /home/pfortuny /usr/bin/rsync -av -e "ssh -i /home/pfortuny/.ssh/backup_key" --filter ": .rsync.dirs" \ ~/ pfortuny@remote.server.mine:"~/backup/" Comments: The option -av is expanded to -vlogDtpr on the server, ...
  • 12.24.08
    screen: a short list of commands shell | pfortuny | (0)
    Having already introduced screen in detail, I am now listing some specific commands. Recall that once a screen "session" is started, in order to get a screen command executed, you need to press C-a (that is, Ctrl and a) and then another key (C-a is the prefix for 'screen' and the other key is the specific command). To the point (notice that commands are case-sensitive): C-a c (we mentioned this one in the previous article): create a new screen (and give it the focus). C-a S: split the tty in "one part more". If a screen occupies the whole terminal, this command splits ...