The Archives

  • 28.Apr.09
    A cron exception shell | rafacas | (0)
    Some time ago a workmate asked me why the next cron line didn't work: 0 0 1 * 1 script The script runs every monday at 00:00 and not only the mondays 1th, which should be the expected behavior. That is because of a cron exception. A job is executed when all the time/date specification fields match the current time and date, but if both the day of month and the day of week are restricted (not "*"), then either the day of month or the day of week field must match the current day (even though the other does not).
  • 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.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.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: $ ./currencies.sh 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 ...
  • 18.Dec.08
    Cron job every 5 minutes automated, cmd, security | pfortuny | (0)
    $ cat < /var/cron/tabs/pfortuny */5 * * * * /usr/bin/my_task The specified task is run every 5 minutes.
  • 02.Dec.08
    Quiet grep automated, shell | pfortuny | (0)
    Usually during an cron job, one needs to check for an expression in a log file, or in the output of a command, without generating any cumbersone new output (such as a standard grep would do): this is exactly the use of the -q option of grep. For example: for i in `grep -v '^#' /etc/passwd | cut -f1 -d:` grep $i /var/log/samba/log.smbd | grep -q 'failed to authenticate' if [ $? == 0 ] ; then mail -s 'Error in samba' $i <<EOM ...
  • 08.Nov.08
    Is this a tty? shell | pfortuny | (0)
    That is a funny question to ask if you are a human (because you *should* know the answer). But it is not that dumb for a system. As a matter of fact, among the multiple tests the shell admits (man 1 test), there is a -t which serves specifically for that: $ test -t 0 returns 0 (that is, success or true in shell jargon) if the standard input (file descriptor 0) is open and is associated with a terminal. So, unless things are going pretty bad, the following $ test -t 0 && echo $? Should always print a 0. However, when a file ...
  • 23.Oct.08
    Nix all output cmd | pfortuny | (1)
    $ cat /var/mail/* >/dev/null 2>&1 The first redirect sends stdout to /dev/null, the second one sends stderr to stdout, thus making all the output disappear. Useful in cron jobs if you want no mail sent.
  • 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 id_alex.pub. 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 ...