Cron jobs

Cron jobs are perfect for executing a specific task or script at a scheduled time or different time periods.

Cron jobs can be run hourly, daily, weekly and monthly.

Cron configuration file is located:


This file should look like this:

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

Execute a job every X minutes

*/5 * * * * /path/to/script/

Use */10 for every 10 minutes, */15 for every 15 minutes… and so forth..

Execute a job every X hours

0 */5 * * * /path/to/script/

Use */2 for every 2 hours, */3 for every 3 minutes… and so forth..

Execute a job every Xth day of the week

Lets assume you want to execute a cron job every Wednesday at midnight:

0 0 * * 3 /path/to/script/


0 0 * * Wed /path/to/script/

You can use the corresponding number or the three letters for each weekday:


Please note that numbers starts with 0 for Monday, and not 1.

Execute a job every X months

You need to specify the what specific month or months you want to job to be executed. Like January and September:

0 0 1 1,9 * /path/to/script/


0 0 1 Jan,Sep * /path/to/script/

If you only want January and September, you should use a comma. If you want the job to be executed starting January and ending September, you need to use this format: 1-9.


Linux Server under DDOS Attack

To find out what IP is causing the DDOS, we can run the next command:

tail -n 10000 logfile.log | cut -f 1 -d ' ' | sort | uniq -c | sort -nr | more

The top IP addresses would be the ones to block.

Another way is looking at what resources are being requested:

cut -f 2 -d '"' logfile.log | cut -f 2 -d ' ' | sort | uniq -c | sort -nr | more

It’s probably you will see that they are trying to request a specific resource know as a common attack. For example, a common attack to wordpress would be:

GET /index.php? HTTP/1.0

Block IP using iptables

In order to block an IP in our Linux server, we need to use iptables:

iptables -A INPUT -s IP-TO-BLOCK -j DROP
service iptables save

To view all our rules set in iptables:

iptables -S

Change files and directories permissions recursively

To give directories recursively read and execute privilege:

find /path/to/dir -type d -exec chmod 755 {} +

And for files:

find /path/to/base/dir -type f -exec chmod 644 {} +

Block an IP address range using the .htaccess file

I detected an attack to one (compromised) server running Apache and PHP. A fair amount of request were being made to a hacked resource. So one of the steps to avoid so many request was to block the IP range of the attacker(s). This was made via .htaccess in the site configured in apache:

Order Allow,Deny
Deny from XXX.XXX.XXX.0/24

That would stop the attack (for a few moment at least!)


Add words to beginning of file with sed

A few days ago I needed to add a few words to the beginning of each line in a really large file (53,232 lines).

Using a text editor would take a lot of time, so I used the powerfull sed command:

sed 's/^/Your words /' large_file > new_large_file

And that takes less than a second.


Check your internet speed from command line with speedtest_cli

I found this the other day and couldn’t resist.

You can test your internet speed from command line using the python script “speedtest_cli”.

Here’s how to get it:

1. You can install it with pip:

pip install speedtest-cli

or use pip from github:

pip install git+

2. Clone the whole code from github and install it with python:

git clone
python speedtest-cli/ install

3. Or just download the script and execute it.

wget -O speedtest-cli
chmod +x speedtest-cli

How to use it

From the command line:


Typical outout will be:

$ ./speedtest-cli 
Retrieving configuration...
Retrieving server list...
Testing from XXX (XXX.XXX.XXX.XXX)...
Selecting best server based on latency...
Hosted by XXX (XXX) [2.12 km]: 92.277 ms
Testing download speed........................................
Download: 2.73 Mbits/s
Testing upload speed..................................................
Upload: 0.88 Mbits/s

You can even share your results by getting an image of it:

$ ./speedtest-cli --share

Which will generate a png file you can share.

Make sure to check all the option by using:

$ ./speedtest-cli --help

How to clone a virtual machine in Virtual Box

Hey… last night I needed to clone a virtual machine that I have… so… looking around the web I’ve found how to do it…

VBoxManage clonehd /home/user/.VirtualBox/VDI/image.vdi /home/user/.VirtualBox/VDI/image.vdi

By the way… you HAVE to provide absolute paths to VirtualBox images..


Bandwidth control in Linux

I’ve experienced a really weird issue while I’m browsing the web and downloading a file.. it seems that the download takes all the bandwidth of my connection.. well.. after googling around I’ve found these solution for both, Ubuntu and Fedora..


Create the next file


With this content:

Queue-mode "access";
Dl-Limit "65";


Edit the yum.conf (sudo gedit /etc/yum.conf) and add these lines at the end of the file:

# 70% of your connection bandwidth

That’s it…
Hope to be helpful…