Category

scripts

  • 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.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.14.09
    Is your site up? scripts | rafacas | (0)
    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.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 ...
  • 01.17.09
    Less can do more… scripts, shell | n0str0m0 | (0)
    ... more than you think ;) less is a command that allows you to view and move forward and backwards in a file among other things. But the interesting thing is that less allows you to define a preprocessor. You can set it as the form of a shell script specified in the LESSOPEN environment variable. $ echo $LESSOPEN lessopen.sh %s This is the script that will be invoked before the actual less command (located in /usr/bin/less) is executed. The result of the script must be something readable. If you take a look at the script you will find what kind of files can ...
  • 12.16.08
    TTYtter: twitter client for real commandliners scripts, shell | rafacas | (1)
    If you are a twitter adict (I know you are already a commandliner ;) TTYtter is your client. TTYtter requires only Perl 5.005 or better, and either cURL or Lynx. It supports encryption as long as your Lynx or cURL does. If your client supports it you can configure TTYtter to use SSL changing the relevant URLs. These can be changed using TTYter options (-url, -rurl, -uurl, -wurl, -update, -dmurl and -frurl) or you can cut and paste the following code into your .ttytterrc file in your $HOME directory: url=https://twitter.com/statuses/friends_timeline.json rurl=https://twitter.com/statuses/replies.json uurl=https://twitter.com/statuses/user_timeline wurl=https://twitter.com/users/show update=https://twitter.com/statuses/update.json dmurl=https://twitter.com/direct_messages.json frurl=https://twitter.com/friendships/exists.json The default cURL's certificate bundle is old and may not support Twitter's current ...
  • 12.12.08
    awk specifying the field separator cmd, scripts | pfortuny | (0)
    $ awk -F'=| ' '{print $3}' < code.pl Prints the third field in each line of regr_FF, using the regexp '=| ' as the field separator (FS). The example regexp means "either an equal sign or a space'.