Friday, January 11, 2013

Debian / Ubuntu Package Commands ( apt-get / apt-file / apt-cache )

sudo apt-get update
sudo apt-get upgrade --dry-run
sudo apt-get upgrade

apt-cache search maven     # too much information
apt-cache search ^maven$   # misleading information
apt-cache search mvn       # no information

apt-file search mvn            # too much information
apt-file search ^mvn$          # no information

which mvn
apt-file search /usr/bin/mvn   # glory

apt-cache show maven2          # description and dependencies
apt-cache showpkg maven2       # package info
apt-cache showsrc maven2       # source files

Thursday, January 10, 2013

Website Debugging with Curl : The Web Browser of the Gods

The Web Browser of the Gods

watch -d -n 1 curl -sv -b cookiejar.txt -c cookiejar.txt http://localhost:8080

For Gods who are mostly interested in the headers:

watch -d -n 1 curl -sv -b cookiejar.txt -c cookiejar.txt -o http://localhost:8080

Long Version

Curl's a nice way to analyse what's going on with a website:

When debugging a server running on your own machine:

curl http://localhost

If it's on port 8080

curl http://localhost:8080

If you're after a sub-path

curl http://localhost:8080/favicon.ico

I prefer:

curl -sv http://localhost:8080

-s turns off the information about download percentage, progress
-v adds the details of the header transaction

You can send both data and progress messages to a file with:

curl -sv http://localhost:8080 2&>curl.out

Poll the website every second, highlighting changes with:

watch -d -n 1 curl -sv http://localhost:8080

Pass in a cookie thus:

curl -sv http://localhost:8080 -b "yo=doom"

See the cookies that come back:

curl -sv http://localhost:8080 -c -

Save cookies that come back:

curl -sv http://localhost:8080 -b "yo=doom" -c cookiejar.txt

Or read and write cookies from a cookie file like:

curl -sv http://localhost:8080 -b cookiejar.txt -c cookiejar.txt

Finally, you can throw away the document itself and just display transaction and the cookies with:

curl -sv http://localhost:8080 -b "cook=ie" -c /dev/stderr >/dev/null

Monday, January 7, 2013

List Source for Bash Functions

If you use alias, then just typing alias will give you all the defined aliases, and alias alias_name will tell you what a particular alias does. For functions defined in .bashrc and other places, you can use:

    declare -f

which will give you the names of all functions currently defined, and:

    type function_name

which will give you the source for a particular function.

(declare -F will give names and sources, like alias does, but it's usually too much information)