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:

sudo aptitude install fdupes
#!/bin/bash
 
OUTF='rm-dups.sh'
echo "#!/bin/bash" > $OUTF
fdupes -r -f $1 | sed -r 's#(.+)#rm '\"'\1'\"'#' >> $OUTF
chmod +x $OUTF

Sample firewall script for Hardy Heron

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:

#!/bin/bash
 
  ## set the default policy to drop (deny) all connections
  sudo ufw default deny
 
  ## set logging ON
  sudo ufw logging on
 
  ## permit unrestricted traffic from a specific static IP address
  sudo ufw allow from 192.168.1.1    # maybe your router
 
  ## permit TCP connections on ssh port 22
  sudo ufw allow 22/tcp
 
  ## Allow Apache2
  sudo ufw allow 80/tcp
 
  ## Allow MySQL
  sudo ufw allow 3306/tcp
 
  ## Allow Bittorrent
  for port in {7881..7889};
  do sudo ufw allow $port/tcp; done
 
  ## Allow eMule
  sudo ufw allow 4662/tcp
  sudo ufw allow 4672/udp
 
  ## Allow DC++
  sudo ufw allow 6845
 
  ## Allow Samba from internal network only 
  sudo ufw allow proto tcp from 192.168.1.0/24 to any port 135 # used by smbd
  sudo ufw allow proto udp from 192.168.1.0/24 to any port 137 # used by nmbd
  sudo ufw allow proto udp from 192.168.1.0/24 to any port 138 # used by nmbd
  sudo ufw allow proto tcp from 192.168.1.0/24 to any port 139 # used by smbd
  sudo ufw allow proto tcp from 192.168.1.0/24 to any port 445 # used by smbd
 
  ## Display rules
  sudo ufw status

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

sudo update-rc.d FOO defaults

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

sudo chmod +x FOO

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:

sudo update-rc.d -f FOO remove

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close