How to make a script sleep for a random amount of seconds

Reading Time: < 1 minute

If you want to insert a sleep in a script for a random number of seconds, you can do the following:

        NUMBER=$[ ( $RANDOM % 60 )  + 1 ]
        sleep $NUMBER

Replace 60 with the interval chosen and you will get a random sleep between 1 and 60 seconds.

This can be useful if you are trying to fetch data from a server who’s monitoring the number of connections you are opening and tends to blacklist you if you do too much.

How to forward a lot of emails with Mutt

Reading Time: < 1 minute

Today I had to forward 2200 emails from a mailbox to another address. I looked around a bit to find a way to automate this process but all I could find was how to forward new messages.

That’s easy, just put a .forward file in your home dir with the email where you want to forward and it works.

But to forward already received email, it’s a bit trickier.

I was already using Mutt and I know it is a very powerful tool so I looked a bit more into it.

In order to solve my problem I found the following:

You can Tag many messages with this command:

T.*

Then execute one command on all the message tagged with this:

;b

It will then ask you the email address where to bounce all this emails.

Fill it in and off you go. It took 3 minutes to send the 2200 mails. Cool 🙂

Then you can easily delete all these files with this:

;d

How to download a youtube video under linux command line

Reading Time: < 1 minute

Here is a great python script very useful to download an HD video from Youtube using the command line in Linux.

https://rg3.github.com/youtube-dl

It’s very simple, download and run. The result is an mp4 file that you can watch offline with VLC or Media Player Classsic under Windows or any other mp4 player under Linux.

Fix a ubuntu upgrade problem with Grub2

Reading Time: < 1 minute

With Ubuntu 10.04 came a new version of Grub. During an upgrade from a previous version to 10.04 or higher there will be a time when the system will ask you if you want to keep your own version of the configuration or get the package maintener version.

If I am not mistaken, you should say you want the maintener one.

But then something strange may happen depending on your upgrade path.