The Archives
-
04.20.09Monitoring HTTP requests from the command lineSome days ago Javisantana sent me a tweet with a link to a one-liner HTTP requests monitor. It goes as follows with some ouput added: $ sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*" Password: tcpdump: listening on en1, link-type EN10MB (Ethernet), capture size 65535 bytes GET / HTTP/1.1 Host: commandliners.com GET / HTTP/1.1 Host: google.com GET / HTTP/1.1 Host: www.google.com GET / HTTP/1.1 Host: www.google.es GET /intl/en_com/images/logo_plain.png HTTP/1.1 Host: www.google.es [...] Replace en1 with your network interface's name. Usually enX in BSD-like OSes and ethX in Linux. You can create an alias named httpdump and add it to ~/.bash_profile: alias httpdump='sudo tcpdump -i en1 -n -s 0 -w ...
-
04.17.09Showing a computer’s open ports$ netstat -an | grep -i listen Shows the open ports on all the IPs of the computer the command is run on.
-
03.04.09Removing blank lines from a fileSometimes I need to remove blank lines from a specific file. I usually do it with the two following commands: $ grep -v "^$" file or $ sed '/^$/d' file Obviously, if you want to save the output you should redirect it to another file, for example: $ sed '/^$/d' file1 > file2
-
02.14.09Is your site up?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.02.09Currency conversion scriptIn 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 ...
-
12.02.08Quiet grepUsually 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 ...
-
10.25.08Recursive grep in Solaris$ find . | xargs grep PATTERN In Solaris, the grep command does not have the -R (-r, --recursive) option which reads all files under each directory, recursively. The above command can be used to do the same in Solaris.
-
07.01.08Time of last system shutdown$ last -x | grep shutdown | head -1 shutdown system down 2.6.24-16 Tue Jun 24 13:31 - 15:08 (01:37) This command displays the time of the last system shutdown.