The Archives

  • 20.May.10
    echo -n woes scripts, shell | pfortuny | (2)
    It took me quite a while to realize that the following line does not do what you think it does: $ echo '$1$CSmo96nX$G0PL/Cs/of5qDN2vMnyHp0' | openssl base64 | tr -d '\n' You should always use the -n option if you want to make sure there is no spurious trailing newline: $ echo -n '$1$CSmo96nX$G0PL/Cs/of5qDN2vMnyHp0' | openssl base64 | tr -d '\n' (By the way, the encrypted message says just 'patata0' and it is not my password). Or... is it? Tested on two Linux systems (Fedora & Ubuntu) and one Snow Leopard.
  • 26.Apr.09
    Command line Russian roulette fun | rafacas | (1)
    $ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo Click Please notice that this is a fun command before copying and pasting. Via | xeoncross tweet.
  • 10.Mar.09
    Converting filenames to lowercase cmd | rafacas | (0)
    $ for i in *; do mv "$i" "$(echo $i|tr [:upper:] [:lower:])"; done Turns all uppercase characters in the present directory filenames into lowercase. There is no collision detection, so if some name gets repeated, the destination file will be overwritten and the first file will be lost. Use the above if you know that there will be no collisions.
  • 14.Feb.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 and the script is: #!/bin/bash # # 2009 - Rafa Casado - numargs=$# if [ $numargs -ne 1 ] then echo "Usage: $0 domain" echo "Ex: $0" exit 1 fi DOMAIN=$1 IS_UP=`wget -nv -O ...
  • 02.Feb.09
    Currency conversion script scripts | rafacas | (1)
    In this time of crisis perhaps we need to pay more attention to financial issues. I am interested in converting some currencies so I have written a script that given two currencies, converts on to the other. The script searches the info on Google Finance's page. An example of its usage is: $ ./ EUR USD 1 EUR = 1.316 USD The available currencies are: EUR - Euros USD - United State Dollar GBP - British Pound JPY - Japanese Yen CHF - Swiss Franc CAD - Canadian Dollar AUD - Australian Dollar INR - Indian ...
  • 17.Oct.08
    DHCP, inverted commas and ssh with RSA automated, security | pfortuny | (1)
    There is a server I manage (called alex) which has not a fixed IP. As you know, I have a shell at the best Unix server out there (by the way, it is almost free. The problem is to keep an up-to-date record of the first server's IP address. I do it as follows (and yes, I know timtowtdi). What I did was: Create an RSA public/private key pair at alex: alex $ ssh-keygen -N'' -f 'id_alex' -t rsa which creates the files id_alex and Create a cron job for my account at alex which looks like 5,10,15,20,25,30,35,40,45,50,55,0 * * * * /usr/bin/ssh -i ...
  • 05.Oct.08
    Moving around shell | fernape | (0)
    One of the things that annoys newbies the most is moving around using a shell. Most people thing it is easier and faster if you use the mouse and goes clicking around. The fact is that shells provide a lot of useful features for efficiently traversing the filesystem hierarchy. Here are some hints. Note: Some of the features may vary from a shell to another or even between different versions of the same shell. I will use bash 3.00 for this post. The basics If you want to change to another directory, you use the following command: $ cd This is easy enough and probably ...
  • 08.Sep.08
    IP data of an ssh connection cmd | pfortuny | (0)
    $ echo $SSH_CLIENT 50849 22 Shows the IP data of the ssh connection this tty is linked to.
  • 17.Jul.08
    Roll the dice scripts | fernape | (5)
    Not a command, but a fun thing anyway. What if you need a dice (as I needed the other day while trying to play a game with my friends) and you don't have one? Bash can do it: $ while true;do let dice="$RANDOM % 6"; let dice=$dice+1;echo $dice;read;clear;done Though it's a long line, this is just an infinite loop in which we use the $RANDOM bash variable which generates a random number between 0 and 32767. After that, we divide it by 6 and take the remainder (so we have a number between 0 and 5) and add 1 to shift the interval ...