# Read random pastes from pastie.org ;) #!/bin/bash echo Fetching paste list ... lst=`wget pastie.org/pastes -q -O - | grep "id='paste" | head -n 1 | sed "s/.*id='paste_\([0-9]*\)'.*/\1/"` echo Newest paste is $lst. r="" while :; do rnd="$(ruby -e "$><<1+rand($lst)")" echo -e "\n"Looking up paste $rnd ... wget http://www.pastie.org/pastes/$rnd/download -q -O /tmp/paste-$rnd if [ -s "/tmp/paste-$rnd" ]; then grep -q "

Sorry, there is no pastie #$rnd or it has been removed\. Why not create a new pastie?

" /tmp/paste-$rnd if [ "$?" = "0" ]; then echo Paste $rnd does not exist. else less /tmp/paste-$rnd echo -n Save?\ read r [ "$r" = "y" ] && echo Saving as paste $rnd in $HOME && cp /tmp/paste-$rnd $HOME fi; else echo Empty paste. fi; rm /tmp/paste-$rnd echo -n Quit?\ read r [ "$r" = "y" ] && exit done;