Glob for multiple file extensions

I’m working on a script that I’m using to rename files from my various digital cameras.  I typically use three cameras when travelling – a DSLR or MILC body, a compact, and my phone.  I want to rename the files with the date the timestamp, prepended to the file name.

I need to find the correct files, and rather than just taking a chance on all files found in a directory, I’d like it to search for specific files. Here are a list of the formats I have:

2015-01-31 08.12.41.mov
00014.MTS
P1000756.MP4
IMG_2102.MOV
C0014.MP4

So to get a list of these files in the current directory, I have the following:

ls -A [C,P]*.MP4 [1-9]*.MTS IMG*.MOV

This gives me a simple list of files that I can feed into the a for loop to read the timestamps and rename the files.

If you noticed that the glob doesn’t include anything to match .mov (lower case) files, this is intended. The only camera I own that produces lowercase .mov files already use a timestamp as the file name.

There are more elegant ways, if you don’t have specific file name conventions that go with specific extensions. Here’s an example:

ls -A [1-9,C,P,I]*.{MOV,MTS,MP4}

Hope this helps someone!

First post!

For the past decade or so, I’ve maintained about a dozen different blogs.  No, that sounds wrong.  Failed to maintain.  Yes, I failed to maintain about a dozen different blogs.  These were differentiated by their specific topic or sub-topic, and who they were aimed at.

Some were out out the public internet, some were internal only at my work and would require some redactions.  At least one was meant to be public, but I restricted it to my home IP early on and never removed that restriction.

Well, I think it’s to do something about this.  Over the next year or so, I’m going to consolidate everything into this blog.  Some articles require a fair deal of clean up, others need to have identifying information removed.  There’s  lot that’s now technically obsolete.  I mean, who’s debugging obscure dovecot mbox parsing bugs introduced – and subsequently fixed -by a RHEL4 update?  Well, on one of my blogs, the article dealing with this is still the most popular.  So, for posterity I will port these articles too, and do my best to backdate them appropriately.

ServerSignature and ServerTokens

ServerSignature and ServerTokens are two variables that determine how the Apache server describes itself, which makes it useful to keep some secrets.   While obscurity is not security, it’s nevertheless a good idea not to save a potential attacker time by giving them the exact versions of everything you run on your server.

ServerTokens

ServerTokens describe how much information about itself Apache divulges, both in the HTTP headers, and in the signature on server-generated pages, such as errors and directory indexes.  Here are the possible settings and example values:

Full:  Apache/2.2.3 (Red Hat) mod_ssl/2.2.4 OpenSSL/0.9.7l DAV/2 mod_fastcgi/2.4.2 PHP/5.1.5 mod_jk/1.2.15
OS: Apache/2.2.3 (Red Hat)
Minimal: Apache/2.2.3
Minor: Apache/2.2
Major: Apache/2
ProductOnly:  Apache

ServerSignature

This describes how Apache refers to it
self in server-generated pages.  Possible values are On, Off or EMail.  On will give a message like:

Apache Server at www.example.com Port 80

Where “Apache Server” is the result of the ServerTokens value.  Setting ServerSignature to EMail, will give something like (note the mailto link):

Apache Server at www.somerandomstuff.com Port 80

And finally, setting it to Off, will show nothing.

Plesk: How many ColdFusion sites?

A customer asked how many ColdFusion sites they had on their Plesk server. Ordinarily, the following query would make this easy to answer:

# mysql psa -e "select count(*) as 'Coldfusion Enabled' from hosting where coldfusion = 'true'"
+--------------------+
| Coldfusion Enabled |
+--------------------+
|                159 |
+--------------------+

In their case, however, they had ColdFusion support enabled for all sites, so we needed to find out how many domains actually had ColdFusion content. Here’s a quick&dirty one-liner:

# find /var/www/vhosts/ -type f | grep -i "\.cfm" | cut -d/ -f5 | sort | uniq | wc -l
   150

Mac OS X Sleep Modes

There are two ways that computers sleep (a.k.a. being suspended). One way is to keep the RAM powered on, and turn the rest of the computer off (suspend to RAM). This allows the computer to wake almost instantly. The disadvantage is that if your computer loses power – say, the battery runs out – you lose your session, and your computer will boot up normally when you turn it on.

The second way is to write the contents of RAM to the hard disc, and turn the computer off completely (suspend to disc). This way you can unplug it or disconnect the battery, and you won’t lose your session. The disadvantage is, it takes longer to sleep and to wake. The more RAM you have, the longer it takes. Current MacBook Pros can have 16GB of memory, which can take a couple of minutes to write to and read from disc.

Recent versions of OS X, at least from 10.5, possibly earlier, ships with its sleep mode configured to do both of the above. This works great! You get fast wake-up times, but if your battery runs out, you don’t lose your session either. On older MacBooks/MacBook Pros this means that you can swap out the battery, and still have your session in tact.

The sleep modes are configured by the ‘hibernatemode’ directive, and you can check yours as follows:

$ pmset -g | grep hibernatemode

	hibernatemode  3

The hibernate modes are as follows:

0: Suspend to RAM. RAM remains powered on while sleeping, safe sleep is disabled, wake is instant.
1: Suspend to disc, a.k.a safe sleep. RAM contents is written to disk, computer shuts down completely. Slower to wake up.
3: RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping.
5: Same as mode 1, but for using secure virtual memory.
7: Same as mode 3, but for using secure virtual memory.

Of course, mode 3 still means that your shiny MacBook is spending a fair bit of time writing to disc every time you close the lid. Even my 2008 vintage MacBook Pro can go about a month in mode 0 or 3 before the (now 5 year old) battery runs out. So for all practical purposes, suspend to disc is completely unnecessary. To set it to 0, do the following:

$ sudo pmset -a hibernatemode 0

Once you’ve set it to 0, you can free up some space by removing the RAM image:

$ sudo rm /var/vm/sleepimage

Konsole and the console font

After doing some updates on my Debian Lenny workstation, I noticed that KDE’s Konsole is no longer able to find the “Console” font, and upon trying to install it, I’m greeted with an error saying:

Could not install console8x16.pcf.gz into fonts:/Personal/

Fortunately, this is easily fixable. As root, run the following:

# dpkg-reconfigure fontconfig-config

Choose the default option to all but the question about bitmap fonts – choose YES here. This will enable support for bitmap fonts. Then do:

# dpkg-reconfigure fontconfig

This will update the font cache. Now restart your Konsole, and your fonts should be back to normal.

Update 2009/03/07:   I had this happen to me again today (did a dist-upgrade to Squeeze) and after running the above fix, only one of the two missing fonts returned.   I found that removing the contents of ~/.fontconfig/ does the trick.

Update 2009/07/25:   I got a new PC at work, and this time did a clean install of Squeeze, which meant getting dumped into KDE4.  Again, the font was missing, and the font installer wouldn’t see the pcf file.  I had to do the above, and then, using the font installer, had to type *.pcf  in the filter field – this installed the font.  I also had to set font anti-aliasing to “enabled” instead of “system settings” in the System Settings panel –> Appearance –> Fonts.

AMOD trouble

I use an AMOD AGL3080 GPS logger in my photography. For a few days now, I cannot get it to do anything. The storage light stays on, but nothing happens. I thought that I’m out of disc space, maybe the trash is taking up all the free space? But that seemed not to be the case – I had 112MB free.

Today I got to look at this more closely for the first time. In the .Trashes directory, there is a ‘501’ directory, and under that, I get the following:

$ ls -lha
ls: QžÇØ\026gYø.œ?\036: No such file or directory
ls: ýdßÞæer˜.^ín: No such file or directory
$
$ rm *
rm: cannot remove `QžÇØ\026gYø.œ?\036': No such file or directory
rm: cannot remove `ýdßÞæer˜.^ín': No such file or directory

Eventually, I gave up and plugged it into a linux box. Now the ‘501’ didn’t show up as a directory any more, but as a file. rm -rf, unmount it, switch it on, and what do you know, it’s working! I’m not sure if just deleting the 501 from the terminal in OSX would have worked, it probably would have. I just find it strange that it showed up as a directory and not a regular file.

Colour profiles in Firefox 3

Firefox 3 adds support for colour profiles – finally! But (isn’t there always a “but”?) it is not enabled by default. To enable colour profiles, type the following into the address bar:

about:config

Read the warning and take it serious. Click the button to proceed. Now, in the “Filter” bar, type:

gfx.color

This will give three results. The second result should be:

gfx.color_management.enabled

and it should be set to false – double click on it to set it to true. Now restart your browser, and you’re all set.

Migrating a MySQL database containing views

You may have come across this problem: say you have a MySQL database called ‘myblog’ which you’re moving to a new server on a different provider, and said provider doesn’t allow you to name the database, but instead use their own scheme, ‘user82_db1’ for example.

If you happen to have views in your database, this will cause the import to fail, as those views would still refer to ‘myblog’ instead of the new database. Fortunately, this is easily fixed using the ‘rpl’ command. Say your database is backed up as ‘myblog-backup.sql’:

# rpl "\'myblog\'." "\'user82_db1\'." myblog-backup.sql

This will replace any instance to ‘myblog.’ with ‘user82_db1.’ and allow you to import a working database.

Plesk: Finding large log files

I get this kind of problem every day: “We’ve run out of disc space on our Plesk server – what’s taking up all the space?” The answer, almost every time, is “logs.” Plesk doesn’t enable log rotation by default, so logs can end up taking a lot of space.

Here’s something I cooked up to list the size of each domain’s log directory:

Continue reading “Plesk: Finding large log files”