Kasablanca is a GUI FTP client, which I regularly use. Today, I needed to change the permissions on a folder to allow writing by the web server. After trying for a long time to do it in kasablanca, I found the solution: At the command-line, write:
$ lftp -u tim ftp.example.com
Password:
lftp tim@ftp.example.com:~> cd the/directory
lftp tim@ftp.example.com:the/directory> chmod 777 the_file
I am currently moving a WordPress blog from one server to another. In the process, I messed up the MySQL database transportation, resulting in some tables being created, and some rows being inserted. It would not be possible to simply run the SQL dump files again, since that would result in duplicate rows. This was easy to fix with some commandline and perl magic, though. The file containing all SQL statements is called wordpress-dump.sql (in this example).
First, find the names of all tables:
$ grep -E '^CREATE TABLE' wordpress-dump.sql
CREATE TABLE `cat_visibility` (
CREATE TABLE `comments` (
CREATE TABLE `links` (
CREATE TABLE `movie_ratings` (
CREATE TABLE `options` (
CREATE TABLE `photopress` (
CREATE TABLE `postmeta` (
CREATE TABLE `posts` (
CREATE TABLE `pp_cats` (
CREATE TABLE `sk2_logs` (
CREATE TABLE `sk2_spams` (
CREATE TABLE `term_relationships` (
CREATE TABLE `term_taxonomy` (
CREATE TABLE `terms` (
CREATE TABLE `usermeta` (
CREATE TABLE `users` (
Next, reformat those lines into DROP queries.
$ grep -E '^CREATE TABLE' wordpress-dump.sql | perl -pe 's/CREATE/DROP/; s/ *\($/;/;'
Now, you won’t have to change those by hand!
I decided to upgrade from my current deluge-torrent (a BitTorrent client) to the latest version 0.5.7.1, as I just got a what.cd invite. Unfortunately, the .deb package from the Deluge site didn’t work instantly.
tim@royalgala:~/Desktop$ sudo dpkg -i deluge-torrent_0.5.7-1_i386.feisty.deb
Selecting previously deselected package deluge-torrent.
(Reading database ... 158322 files and directories currently installed.)
Unpacking deluge-torrent (from deluge-torrent_0.5.7-1_i386.feisty.deb) ...
Setting up deluge-torrent (0.5.7-1) ...
tim@royalgala:~/Desktop$ deluge
Traceback (most recent call last):
File "/usr/bin/deluge", line 45, in <module>
import deluge._dbus as dbus
ImportError: No module named _dbus
Googling for “No module named _dbus” gave me only two results, both Deluge-related. The first forum thread had no solution. dpkg purging the system from deluge-torrent did not solve the problem. In the second thread, the problem was solved through manually deleting all files from the previous installation, which is what I did, using slocate. Deluge 0.5.7.1 would then install nicely.
I decided to install the GD image library for Perl on my working station, and as usual, using CPAN. However, after running install GD, I was faced with an error.
make: *** [GD.o] Error 1
LDS/GD-2.35.tar.gz
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Failed during this command:
LDS/GD-2.35.tar.gz : make NO
Unable to find the cause, I turned to apt-get, which installed GD without any problems.
$ sudo apt-cache search libgd perl
libgd-gd2-perl - Perl module wrapper for libgd - gd2 variant
libgd-graph-perl - Graph Plotting Module for Perl 5
libgd-text-perl - Text utilities for use with GD
ruby1.8 - Interpreter of object-oriented scripting language Ruby 1.8
calamaris - log analyzer for Squid or Oops proxy log files
libgd-barcode-perl - Library to create barcode images (GD::Barcode)
libgd-gd1-noxpm-perl - Perl module wrapper for libgd (old version against GD 1.8.x)
libgd-gd1-perl - Perl module wrapper for libgd (old version against GD 1.8.x)
libgd-gd2-noxpm-perl - Perl module wrapper for libgd - gd2 variant without XPM support
libgd-graph3d-perl - Create 3D Graphs with GD and GD::Graph
libgd-perl - Perl module wrapper for libgd
libgd-securityimage-perl - Security image (captcha) generator.
libgdk-pixbuf-perl - Perl module for the gdkpixbuf library
$ sudo apt-get install libgd-perl
Done!
Yesterday, I was transferring a blog from one server to another. I had SSH access to the server which the blog was moving from, and FTP access to the one which it was moved to. The simple solution in this situation is to use a command-line FTP client to simply upload everything. I tried, but encountered a problem.
Using the native ftp command, which comes with virtually every Linux distribution, I found the mput (multiple put) command. However, trying to use it with wild-cards didn’t work, since only the files in the base directory were uploaded. Trying things like mput */* only resulted in strange errors about existing files not existing. I went to look for a new text-based FTP client, which would be usable through SSH, and found lftp, which apparently was installed as default on my system.
lftp has a handy mirror command, similar to the wget –mirror option. Adding the -R (reverse) argument to mirror, recursive uploading became a piece of cake. Just do mirror -R when in the correct local and remote directories.
ttyrec is a great program for recording a terminal. I use it for recording nethack games. Any command is easily recorded with the “-e” argument of ttyrec, which allows you to choose a single command to record instead of the whole shell session. For example, I could type
In order to start nethack, recording the whole game. Or rather, if I want to save the recorded game to a file other than the default “ttyrec”:
$ ttyrec game00 -e nethack
However, I don’t want to nethack. My name is Tim, and I want to nethack -u Tim. Simply adding -u Tim to the previous code does not work, since “-u” is interpreted as another switch for ttyrec. Quotation marks solve the problem:
$ ttyrec game00 -e "nethack -u Tim"
You can easily make a bash script out of this. The following is my playnethack, which is run instead of the regular “nethack”.
#!/bin/bash
echo -n "Name?"
read pname
ttyrec ~/nethack/rec/$pname-`date +%Y%m%d%H%M%S`.tty -e "nethack -u $pname"
Note that the filename here is dynamic. The text within backticks (”`”) is executed as a command, and the command is then substituted with its actual output. date +%Y%m%d%H%M%S returns the current date and time in a format such as 20070613233807. Thus, if I ran the “playnethack” command and set my name to “Tim”, my complete game would be recorded into the file “~/nethack/rec/Tim-20070613233807.tty”, probiding the ~/nethack/rec/ directory existed.
The sister command of ttyrec is ttyplay, which plays the recorded .tty files. Simply do:
$ clear
$ ttyplay ~/nethack/rec/Tim-20070613233807.tty
And you will watch my game, from the beginning to the end. The time is recorded, too–you will know exactly for how long I contemplated each and every action. Using the ttytime utility, you can find out how many seconds long a recorded game is before playing it, e.g:
$ ttytime ~/nethack/rec/Tim-20070613233807.tty
71946 ~/nethack/rec/Tim-20070613233807.tty
However, if you don’t want to wait for 71946 seconds while watching the replay, you can always press any button in order to forward to the next movement. If you hold a key, you will fast-forward through the entire game.
It is even possible to watch a live game as it is being played, using “-p”:
$ ttyplay -p ~/nethack/rec/Tim-20070613233807.tty
This will let you watch my NetHack game as it progresses in real-time, and thus lets you tell me as soon as I make a stupid mistake.
If you keep seeding torrents that have been removed from a tracker, some trackers will harass you with messages like the following, from OiNK:
You have at least one torrent in your client that’s been deleted from our system. Right now it keeps announcing uselessly to the tracker. Please stop or remove all OiNK torrents that don’t exist on our site any more. You will get this message once for every 100 announces you make for nonexistent torrents.
It is simple to identify which torrents are not left on the tracker in Deluge (0.5.1). Just look in the “Status” column. Probably, most torrents will say either “Seeding” or “Leeching”. Look for torrents that stay at “Connecting” for a long time–that’s probably what you’re looking for. Select them and press the “Remove Torrent” icon, making sure not to remove the data.
Problem solved!
Getting tired of the simplicity of the original BitTorrent UI and the memory-hogging of Java-based Azureus, I recently turned to Deluge. According to Wiktionary, deluge is (paraphrased):
- A great flood or rain.
- An overwhelming amount of something
- The Deluge: The Biblical flood during the time of Noah.
- (transitive) To flood with water.
- (transitive) To overwhelm.
It also happens to be a handy, well-featured and good-looking BitTorrent client for Linux. However, since it is still in beta, there is naturally faulty documentation and some other problems. It worked great from scratch, but then I decided that I wanted to divide my torrents into two categories–checked out and not checked out. The announced Categorize plugin seemed optimal for this purpose, and thus, I proceeded to download it from the Plugins page of the Deluge wiki:
$ cd ~
$ wget http://www.icebeach.de/categorize.tar.gz
I opened the tarball and found three files:
$ tar xzf categorize.tar.gz
$ ls
categorize.jpg
Categorize/cat.glade
Categorize/plugin.py
Unable to find instructions on how to install the plugin, I did an slocate to find the other plugins. That plugin.py file seemed pretty generic, so I searched for others.
$ sudo slocate -u
$ slocate plugin.py
/home/tim/Categorize/plugin.py
/usr/share/deluge/plugins/TorrentCreator/plugin.py
/usr/share/deluge/plugins/NetworkGraph/plugin.py
/usr/share/deluge/plugins/ExamplePlugin/plugin.py
/usr/share/deluge/plugins/NetworkHealth/plugin.py
/usr/share/deluge/plugins/TorrentSearch/plugin.py
/usr/lib/gimp/2.0/python/gimpplugin.py
/usr/lib/gimp/2.0/python/gimpplugin.pyc
Evidently, the files should be placed in /usr/share/deluge/plugins. So I did:
$ cd /usr/share/deluge/plugins
$ sudo tar xzf ~/Desktop/categorize.tar.gz
However, starting Deluge failed. I tried starting it from the command line in order to find the problem, and the verbose output helped a lot.
$ delugeno existing Deluge session
Starting new Deluge session...
deluge_core; using libtorrent 0.13.0.0. Compiled with NDEBUG value: 1
Applying preferences
Pickling state...
Scanning plugin dir /usr/share/deluge/plugins
Loading module HelloWorld
Initialising plugin HelloWorld
Loading module TorrentCreator
Initialising plugin TorrentCreator
Loading module NetworkGraph
Initialising plugin NetworkGraph
Loading module ExamplePlugin
Initialising plugin ExamplePlugin
Loading module NetworkHealth
Initialising plugin NetworkHealth
Loading module TorrentSearch
Initialising plugin TorrentSearch
Traceback (most recent call last):
File "/usr/bin/deluge", line 83, in <module>
start_deluge()
File "/usr/bin/deluge", line 57, in start_deluge
interface = deluge.interface.DelugeGTK()
File "/usr/lib/python2.5/site-packages/deluge/interface.py", line 54, in __init__
self.plugins.scan_for_plugins()
File "/usr/lib/python2.5/site-packages/deluge/plugins.py", line 44, in scan_for_plugins
if '__init__.py' in os.listdir(path):
OSError: [Errno 20] Not a directory: '/usr/share/deluge/plugins/categorize.jpg'
Deluge sees the image file categorize.jpg as a plugin folder. Remove it:
$ sudo rm /usr/share/deluge/plugins/categorize.jpg
and it should work. This was done on Ubuntu 7.04 Feisty Fawn with Deluge 0.5.1, installed through apt-get.