GNU/Linux

Install Drush on a Server You Don't Have Admin Rights To

I've been working with quite a few Drupal sites in the past couple years and recently one of my favorite tools to use has become drush. For those of you who aren't aware of it, drush is a command line utility (drush = DRUpal SHell) that makes management of a Drupal site much more bearable. Drush is a great tool to use and is quite simple to install on your system when you have admin rights to the box but what about those of us on shared hosting systems? For us, we have no admin rights but if you've picked a good hosting company, you'll have command line access and a .bashrc file (or similar e.g. bash_profile depending on your server distro).

Once you have command line access, create a directory on the server where you'll keep any programs you choose to install. I created a "bin" directory in my user's home.

mkdir bin

Once you've created that directory, use wget and the link to the latest drush version to download the tarball.

wget http://ftp.drupal.org/files/projects/drush-All-versions-3.0-beta1.tar.gz

Once it downloads, extract it.

tar xzvf drush-All-versions-3.0-beta1.tar.gz

cd into the newly created directory and make sure the drush* file is executable. If not,

chmod u+x drush

Now you have drush on your system but it would be quite cumbersome to have to type the full path to the executable as well as as the drush options. In order to alleviate this we have two choices: we can either export our PATH or setup an alias in our .bashrc file. I choose the latter, but I'll show you both options. First, however, you'll need to know the full path to the drush executable. Inside your ~/bin/drush directory, execute the following:

pwd

So your full path will be something like: /home/mysite/bin/drush/drush
Onto setting up the shortcuts to only have to type 'drush'

PATH option:

export PATH=$PATH:/home/mysite/bin/drush/drush

.bashrc option:

vi .bashrc

Inside the file, you'll add an alias (press 'i' to enter insert mode)

alias drush='/home/mysite/bin/drush/drush'

then save the file (type :wq)

The downside to using the .bashrc option, however, is that you'll have to start a new terminal session to begin using the alias (or type the same alias in the command line so you can use it this session then any other session you start it reads from the .bashrc). So exit then fire up your terminal again.

From here you can execute the entire suite of drush commands simply by using the word 'drush' followed by any drush options just like you would in a normal drush install.

To recap, simply:

  • open a terminal on your server
  • create a bin directory
  • download and extract drush into the bin directory
  • ensure drush is executable
  • get the full path to the executable then either
  • 1) add the full drush path to your PATH variable
  • or

  • 2) alias drush to the full drush path and restart you terminal session

*note: instead of executing a pwd to get the path to your drush install, you could use ~/bin/drush/drush if indeed your bin is in your home directory but I think it's best practice to use full, human readable paths to alleviate any ambiguity.

Superkill - A Quickie Script for Killing All Instances of an Application

Evolution crashed on me this morning and I kept getting an error message: "Evolution appears to have exited unexpectedly...". Every time I started the application, it provided that message then locked so I went to my trusty command line. I did a ps -ef | grep evo and saw that several evolution-based processes were running:
steven    7885     1  0 09:57 ?        00:00:08 evolution --component=mail
steven    7894     1  0 09:57 ?        00:00:00 /usr/lib/evolution/evolution-data-server-2.22
steven    7918     1  0 09:57 ?        00:00:00 /usr/lib/evolution/2.22/evolution-exchange-storage
steven    7931     1  0 09:57 ?        00:00:00 /usr/lib/evolution/2.22/evolution-alarm-notify 
steven   11346  7715  0 11:12 pts/1    00:00:00 grep evo
I then proceeded to kill each process manually. It's only 4 but it was enough to bring out my inner programmer and solve a repetitive task programatically. So I decided to add a couple more pipes. I looked at the results from the grep'd ps and noticed that all process IDs are in character slots 10-14 so I cut -c 10-14 the processes that were piped in. That printed out as expected so I fed that to kill via xargs and, voila!, all those processes were killed. Not content to have to type all the pipes every time I wanted to do it, I threw the pipe in a BASH script that I lovingly call 'superkill' and take the first argument as the string to grep and kill the returned processes. The code is below:
#!/bin/bash

prog=$1

#echo ${prog}
ps -ef | grep ${prog} | cut -c 10-14 | xargs kill
Simple enough but quite powerful. I then threw the script in my /usr/bin directory so my PATH would pick it up. Now I can just superkill evolution (sounds like a creationist book, I know) and have all the processes ended. Here is the file. Just extract it (tar xzvf superkill.tar.gz) and put the resulting file in your /usr/bin directory. Then superkill away! Of course this code comes with no warranty and you assume all risks. Before you run the script you may want to call a ps -ef | grep <processname> before doing superkill <processname> so you make sure there are no unexpected results. I could echo the resulting process and ask for confirmation, I suppose. Hold for that version (depends if I get feedback it works well enough for my purposes).

Mono Position Statement

Scott James Remnant wrote on behalf of the Ubuntu Technical Board today defending Ubuntu's inclusion of Mono in it's default shipped package. The entire text can be read here: https://lists.ubuntu.com/archives/ubuntu-devel-announce/2009-June/000584.html

I recognize that they are in full rights to include whatever software they choose to include (as long as any licensing requirements are fulfilled) and Mono is free software. We all, at some level of understanding, realize this. The problems that arise most frequently are the patents concerning the .Net technologies. Scott Remnant addresses these concerns in the position statement.

It is common practice in the software industry to register patents as
protection against litigation, rather than as an intent to litigate.
Thus mere existence of a patent, without a claim of infringement, is not
sufficient reason to warrant exclusion from the Ubuntu Project.

While this may be true on a grand scale, it is widely accepted that there have been problems and dire consequences with using patented technologies on open source platforms. If it were not for this precedence, Mono might be much more accepted.

My stance is that I feel that Mono should not be bundled with GNU/Linux distributions just as a precaution against litigation (again, Mono is free software but the technologies it supports is patented). I do think, however, in the pursuit of freedom, that developers must have the choice to develop software using Mono in order to bring .Net technologies to GNU/Linux. Choice is an essential freedom that mustn't be denied. This may sound contradictory to my statement that distributions should leave Mono and Mono-dependent software out of its default install. I state it this way because I feel its up to the individual to take the risk of using software based on patented technologies (that perhaps may lead to future litigation). It is much more preferable for the individual to choose to waive their rights than for a platform they depend on to choose to do so for their entire user base. This is especially important if the owner of the patented technology does choose to enforce their patent and litigate because many users will have grown accustomed to the patented technology and a void will be left, where, conversely, no void will be left if the technology wasn't initially present. My position is for protection of the users as a whole so that each user of a distribution isn't unknowingly reliant on software based on patented technologies because it came bundled with an operating system.

In short: don't bundle it, but make it available.

Quickie: Install Packages from FireFox Address Bar

If you're surfing around in FireFox and don't have a terminal fired up, why waste the extra keystrokes or mouse movements just to install a package? If you already know the package name, you can install from your browser simply by using:

apt:<package-name>

For example I want to install the super excellent diagramming software dia, I simply type:

apt:dia

And a GUI pops up much like it does when you select a package and hit apply in Synaptic.

Install Initial Ubuntu Items GUI

Because of all the great response from the simple shell script, I've created a GUI using Zenity and Bash so that people new to the CLI or those who wish to select and deselect what packages to install or uninstall may do so. You'll be able to play DVDs, listen to your MP3s, have 5.1 Surround Sound playback enabled and more. This isn't a 'how-to' but rather a 'just-do-it'. If you want to know the how-to, just view the source of the script. It's basically doing some simple apt-gets with a GUI front-end.

Below is a screenshot of the window. Just download the shell script here on my server, -- you'll need to extract it (tar xvf ubuntuTasks.sh.tar.gz) then make sure it's executable (chmod +x ubuntuTasks.sh) and execute it (./ubuntuTasks.sh). You'll be greeted with a user-friendly GUI where you can select and deselect items.


steven@steven-laptop:~/fun$ chmod +x ubuntuTasks.sh
steven@steven-laptop:~/fun$ ./ubuntuTasks.sh 

Once you hit OK, you'll have to input your sudo password when it returns to the CLI. It shouldn't prompt you for anything else. Please shoot me a message if you need any help or have any suggestions.

Images from Southeast Linux Fest

So many interesting people, so little time. Go here to learn more about attending the Southeast Linux Fest (SELF) next year.

I'm the grinning nerd in the background helping out at the FSF table -- between the KDE guy in blue and the gentleman in white.
Here are my other FSF comrades.

It was an absolute blast. I hope to see some of you guys and gals there next year. Check out the entire album at http://www.flickr.com/groups/selinuxfest/

Initial Ubuntu Install Items Script

UPDATE: Please go here for the new GUI version of this script that also includes some extra items.
I was actually going to write an entry this morning about packages to purge or install upon a fresh Ubuntu build but Ubuntu Linux Help beat me to the punch. It's a great article and well worth the read. I've modified the list slightly and created a bash script to execute it. The file is here. Just extract it ( tar xvf ubuntuTaks.sh.tar.gz ) make sure it's executable ( chmod +x ubuntuTasks.sh ) and execute it using ./ubuntuTasks.sh
Below is the code inside in case you want to just copy and paste it into your own file:

#!/bin/bash

sudo apt-get remove --purge mono-common libmono0
sudo aptitude install sbackup
sudo aptitude install ubuntu-restricted-extras && sudo aptitude install w32codecs
sudo apt-get install msttcorefonts && sudo fc-cache -fv
sudo aptitude install vlc
sudo aptitude install k3b
sudo perl -pi -w -e 's/\; default-sample-channels \= 2/default-sample-channels \= 6/g;' /etc/pulse/daemon.conf

As always, this code comes with no warranties. I have run it on my system and all is well.

Convert MP3 Files to OGG

For those of us who prefer not to install or not rely on proprietary codecs, we can use Ogg Vorbis to freely listen to our music. It is not illegal to install the ubuntu-restricted-extras to listen to MP3 files (it's illegal for Canonical to pre-install them because they sell distros), and for many people this is a blessing since they don't care so much about 'minor' proprietary issues but just have some greater problem with Windows be it its overbearing market share or instability. For those of us who are trying to wean ourselves away from proprietary software altogether, there is a way to convert your mp3 collection to Ogg. You'll need to install mp32ogg (aptly named). From there its a simple command. I'm currently working on a friendly UI for mp32ogg. Currently OggConvert is a good GUI but is limited -as far as I can tell- to converting one song at a time rather than batch converting a directory. Here are the basic commands for converting your music:

sudo apt-get install mp32ogg
mp32ogg --quality=10 --rename=%t *.mp3

This will convert all files in your current directory. You can also use a --delete flag if you are hardcore and want to rid yourself of your mp3s but you may also want to hold onto them if you have a portable device that doesn't support Ogg Vorbis. You can, of course, modify the quality (1-10) and change the rename (from the manual entry: "Instead of simply replacing the .mp3 with .ogg for the output file, produce output filenames in this format, replacing %a, %t and %l with artist, title, and album name for the track").

I'll keep you updated on my GUI progress.

Remove Mono and Its Minions from Ubuntu

Mono is a tool that provides software to create and run client and server .NET applications of various platforms. One of the concerns many Free Software supporters have with Ubuntu is that it decides for us which proprietary software is good and which is bad. As one blog noted: "If Canonical is to be consistent, I should not have to a a hypocrite about some things and not others." -- specifically in regard to Ubuntu requiring you to install proprietary codecs manually (restricted-extras) but pre-loading software that is used to support a proprietary system.
Here's how to remove the offending program, courtesy of theopensourcerer:

sudo apt-get remove --purge mono-common libmono0

As theopensourcerer notes, you should check with your distribution and needs to see if removing Mono is the right decision for you. For most of us, it is.

Quickie: Deleting Old Files

Many people have the need to delete files older than a certain range. For instance, you may want to remove all podcasts that are older than a certain time period or delete other files that you receive regularly. Making use of the find command and mtime, you are able to delete them with ease.

find . -name *.ogg -mtime +7 -exec rm {} \;

The above one-liner removes all my ogg-based media files in my current directory that are more than a week old. It is best to use absolute paths -- ESPECIALLY IF RUNNING BY CRON. So the cron-safe code looks like this:

find /home/steven/music/ -name *.ogg -mtime +7 -exec rm {} \;

You can also use this with other command such as moving the file, batch renaming them (if you want all older files to have a .bak extension or whatnot), as well as many other uses. To move the files, simply:

find /home/steven/feeds/ -name *.csv -mtime +30 -exec mv {} /home/steven/feeds/old \;

With enough MAN pages and will, you can do all kinds of cool stuff.

Latest Video


only search Coder's Wasteland
Powered by Drupal, an open source content management system

Digg this