Last updated 10 September 2008. Created on 10 September 2008.
Edited by eMPee584. Log in to edit this page.

Some things you can do with bash scripting and a bit of glue closely resemble magic. While often not usable outside a very specific use case, shell scripts can do things in amazingly cool ways with less code. If you are using any clever shell scripts that do something useful, or you just want to show off your applied geekdom, post your script here.

Because shell scripts can use a very compact syntax to execute complex tasks - please be sure you do understand what the script is supposed to do before executing it! Do not simply copy'n'paste code from this site! You can learn (a lot!) more about shell scripting from the Advanced Bash-Scripting Guide.

Looking for support? Visit the forums, or join #drupal-support in IRC.


eMPee584’s picture

Sometimes you don't want to throw on a search engine to crawl for a certain package. Or you just want to have a more condensed overview about the cool things you want to install. This script helps in that it downloads the package file listing from the drupal server, converts the html to text, filters it by your preferred drupal-version, removes the first column from the output and writes it to a file. Very suited for grepping for packages.

wget -O -|html2text -width 150 -nobs|'grep' "\-6.x\-"|sed 's/\[\[   \]\] //' > drupalpackagelist.txt
eMPee584’s picture

colordiff rules :)

mv drupalftp drupalftp.old
wget -qO -|html2text -width 130 -nobs|'grep' "\-6.x\-"|sed 's/\[\[   \]\] //' >drupalftp
colordiff -sy --suppress-common-lines drupalftp.old drupalftp
rm drupalftp.old
eMPee584’s picture

Some people like to live on the edge a bit more than others. If you have the developer version of many packages installed, this script checks for each -dev.tar.gz file if there is a newer version on the server, downloads and extracts it and at the end, reports all updated packages. Useful not only for tracking translation files (be careful with those, those archives do not have a parent folder inside, better put them in their own directory!)..

IFS='' #disable internal field separator, for files with spaces which shouldn't actually be drupal packages
echo "`date`">update.log
for file in *-dev.tar.gz
        cp -p $file $file.tmpcpy
        wget -N --no-proxy$file >> drupaldevupdate.log 2>&1
        if [[ "$file" -nt "$file.tmpcpy" ]]
                tar -xzf $file
                echo "$file updated"
        rm $file.tmpcpy