Bash scripts

Find and replace string in file recursively in a directory

Simple command I don't want to forget that find a string and replace it with another using sed.

Backup all mysql database every hour using mysqlhotcopy

My previous script using mysqldump was slowing down Apache, it became unresponsive for a few seconds, so I wrote this one using mysqlhotcopy. It's much faster and doesn't slow down my webserver.

Howto block DDOS attacks with PSAD and simple iptables rules

I will show you howto install PSAD to block DDOS attacks (distributed denial of service) and port scan on a webserver. Here I will use Ubuntu 8.04 LTS server but it should be very similar on other distro.

PSAD scan iptables log file to generate the attack block. The problem is that when you log ALL packets as shown in other PSAD tutorials, it will slow down considerably your server if it's busy and generate huge huge log files (growing at a rate of 1meg per second or more). With simple iptables rules, we will only log traffic that look suspicious (5 new connections in 5 seconds for example).

Simple bash script to monitor your webserver remotely on different ports version 2

Simple bash script to monitor one or multiple webserver on different ports. I'm sure there is over 100 available programs doing this but I wanted something with small memory usage. Also, I only wanted to be notified once, notifications are receive by SMS on my cell. With the software I was using before, I was getting notified every minute until I could reach a computer and fix the problem or stop monitoring which was quite annoying.

Howto block DDOS attacks on Ubuntu

I will show you howto install PSAD on Ubuntu 8.04 LTS server to block DDOS attacks (distributed denial of service) and port scan.

PSAD scan iptables log file to generate the attack block. The problem is that when you log ALL packets as shown in other PSAD tutorials, it will slow down considerably your server if it's busy and generate huge huge log files (growing at a rate of 1meg per second or more). With simple iptables rules, we will only log traffic that look suspicious (5 new connection in 5 second for example).

Deny or allow countries with Apache htaccess

The following script is using blogama.org IP geolocation API to automatically generate Apache htaccess file to deny or allow specific countries. You can put this script under crontab and the htaccess rules will be automatically updated. Also, it can update multiple htaccess files.

Simple bash script to monitor your webserver remotely on different ports

Simple bash script to monitor a webserver on different ports (here smtp, dns, http & https but it can be customized) I'm sure there is over 100 available programs doing this but I wanted something with small memory usage. Also, I only wanted to be notified once, notifications are receive by SMS on my cell. With the software I was using before, I was getting notified every minute until I could reach a computer and fix the problem or stop monitoring which was quite annoying.

Script to backup all mysql database and upload to FTP

In this howto I will show you a simple bash script that dump ALL mysql databases on your server compressed to GZIP and then make a nice tar.gz file with them and upload it to the FTP of your choice.

Blocking IP address of any country with iptables

In this howto, I will show you how to automatically create iptables rules to block all connection from one country or more. The blocklist is created with an API I wrote and you can use wget to update the blocklist monthly.