Tag Archives: script

Search and remove duplicate files

Here a small piece of code which will search for the duplicates in the path you supply. It will generate a new file which contains the commands for deleting those duplicates.
Make sure you double check the resulting file!
The script requires that you have fdupes installed.
Install it in Ubuntu/Debian by running the following command in your terminal:

Sample firewall script for Ubuntu

I just thought that you might be interested in a small script you can use in Hardy Heron.

It uses the new UFW (Uncomplicated firewall) introduced in this new Ubuntu distro.

The script is well commented, so everything is easy to understand.

Here is the script:

You can modify it by adding/removing rules accordingly.

Backup your MySQL databases automatically with AutoMySQLBackup

If you are a MySQL user and you want to have a disaster recovery solution, or even as a simple backup, you can write small shell scripts based on mysqldump tool.

For this, you need AutoMySQLBackup. It doesn’t have any real requirements (mysqldump of course is needed – in any mysql client package – and gzip or bzip2 to compress the resulting file) and has all the features I was looking for in such a script.

AutoMySQLBackup has all the features I needed: it can backup a single database, multiple databases, or all the databases on the server; each database is saved in a separate file that can be compressed (with gzip or bzip2); it will rotate the backups and not keep them filling your hard drive (as normal in the daily backup you will have only the last 7 days of backups, the weekly if enabled will have one for each week, etc.). It has also some other features (check the project homepage for full details), that I am not using myself (like email logs for example), but other peoples might find interesting.

All you have to do is to modify a few things:

# Username to access the MySQL server e.g. dbuser
USERNAME=dbuser
# Username to access the MySQL server e.g. password
PASSWORD=password
# Host name (or IP address) of MySQL server e.g localhost
DBHOST=localhost
# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
DBNAMES="all"
# Backup directory location e.g /backups
BACKUPDIR="/var/backup/mysql"
# Mail setup
MAILCONTENT="quiet"

You can run the script manually but you will want to enable it in cron
and run daily.

Unp

Unp is a small perl script which makes extraction of any archive files a bit easier. It support several compressors and archiver programs, chooses the right one(s) automatically and extracts one or more files in one go.

Instalation:
sudo apt-get install unp

Usage:
usage: unp file [file]...
file: compressed file(s) to expand

Use -- to pass arguments to external programs, eg. some tar options:
unp fastgl.tgz xmnt.tgz -- -C /tmp

Special option:
-f Continue even if program availability checks fail
-u For Debian packages:
- extract data.tar.gz after each operation
- extract control.tar.gz in control//
For other archives:
- create directory /
- extract contents there

currently supported extensions and formats are
tar[.gz,.bz2], gz, bz2, Z, ar/deb, rpm, shar, rar, arj, zip, LHa, cab, ace,
tnef, uu (mail, news), mime, hqx, sea, zoo, pmd, cpio, afio, lzop

Problem:
It doesn’t extract files from RAR archives with full path!

Adding a startup script to be run at bootup

So you have a script of your own that you want to run at bootup, each time
you boot up. This will tell you how to do that.
Write a script. put it in the /etc/init.d/ directory.
Lets say you called it FOO. You then run

You also have to make the file you created, FOO, executable, using

You can check out man update-rc.d for more information. It is a Debian
utility to install scripts. The option defaults puts a link to start FOO in
run levels 2, 3, 4 and 5. (and puts a link to stop FOO into 0, 1 and 6.)

Also, to know which runlevel you are in, use the runlevel command.

If you want to remove the script, just run: