So I have a mail server configured and I want cron to send me a summary each time it runs the task…

So I have a mail server configured and I want cron to send me a summary each time it runs the task…

Am I asking for to much?

No.

Run:

crontab -e

and add this as a first line:

MAILTO="email@my.domain"

This will tell cron that You want it to send You e-mail to the email@my.domain with a summary after each job was ran.

You have to do this for each user – setting up MAILTO parameter for lets say user john will only send You messages for tasks ran by john’s crontab.

Cheers.

Andrzej

Cron installation and first steps.

Cron installation and first steps.

Cron? What is it…?

Well… Cron is a task scheduler. Its an application that runs as a daemon in the background and can run other applications / scripts / commands at the times scheduled by you. It can run chosen command every 5 minutes or exactly at 12:11 each day, or on every Thursday at 5:05 or right after a reboot and so on and so forth. It can automate some tedious and boring tasks for You.

So how do I get it?

Gain root and then run:

pacman -S cronie

Now You need to enable and start it:

systemctl enable cronie

systemctl start cronie

Now You can start adding tasks.

Adding tasks is easy but You need to know few things.

First of all: your user needs to have the permission to run the task. Cron uses the permissions of the user that the job was added by to run the tasks. What does it means? If You want to run something that needs root access You have to add this task to root’s cron task list. If You want your user john to run something – You add it to the john’s cron jobs list.

How?

Use su command.

For example:

su john

will log You in as john for this terminal session.

But how do I know if I am john?

Ask:

whoami

and the terminal will tell You.

So… IF I want to add a root’s job…

You need to do this:

su

crontab -e

This will open text editor and will allow You to add the task.

Just remember that running stuff as root has its risks and that You should avoid doing it.

I have no idea how to syntax the cron task properly…

Ok – visit this site. It will generate the syntax for You BUT… here is another thing You need to know.

What’s that?

Well – if You want a task to be ran exactly at 12…

Yes yes all I have to do is add:

* 12 * * * /path/to/executable

Yes AND no…

Huh?

This command will be ran at 12.

Awesome…

But it will also be run at 12:01 and 12:02 and 12:03… 12:59…

Awwww… But I only want it to run once…

Yes. You need to be more specific…

Oh… So I need to do it this way?

0 12 * * * /path/to/executable

That is correct. You need to tell cron to start it at exactly 12:00. By specifying hour only You’re telling cron to run this command on every minute of this hour.

Another thing that You may want to know is that there is more than one way to skin the cat…

Huh?

Let me give You and example. I want to run an executable exactly every 6 hours. I can do it this way:

0 0,6,12,18 * * * /path/to/executable

OR I can do it this way:

0 */6 * * * /path/to/executable

That’s neat! But You said that I can also run stuff right after my machine boots up after a reboot. I don’t see how I can specify that value using the time / date.

That is correct. You would have to use @reboot option.

Oh… Cool! So if I want to run something right after cronie starts after reboot I have to add this:

@reboot /path/to/executable

Thats a a roger. You can also use things like:

3 0 * 1 1 /path/to/executable

So this will run the executable on every Monday of January exactly 3 minutes past midnight?

Yup.

So You can use:

crontab -e

to add new or edit current cron jobs and You can also use commands like:

crontab -l

to list all the jobs for the user You are currently logged in as and

crontab -r

to remove all the crontab entries for the user You are currently logged in as.

Oh I think I got it! This cron thing is awesome. It can make life so much easier! Thanks Andy.

You’re welcome Andy.

Cheers.

Andrzej

Changing the default command line text editor to Your favorite one.

Changing the default command line text editor to Your favorite one.

How?

Edit ~/.bashrc and add this:

export EDITOR=mcedit

after this line:

# User specific aliases and functions

So it looks like this:

# User specific aliases and functions
export EDITOR=mcedit

Close terminal and reopen it. Now applications like crontab or newsbeuter will use mcedit as their editor.

You can choose other editor (nano, pico) whatever works for You. Just edit the export line to suite your needs.

This change will only affect Your user. Other users on this system will use the default text file editor. If You have more then one account on this machine and You want all of them use Your favorite text editor – You will have to edit ~/.bashrc for them too.

Cheers.

Andrzej

Fixing postfix / postdrop / sendmail “warning: File too large”.

Hi there!

I have found this in my server logs after trying to send VERY large file using the LAN mail:

Jun 11 09:35:39 icsserver.loc postfix/postdrop[2839]: warning: uid=0: File too large
Jun 11 09:35:40 icsserver.loc postfix/sendmail[2837]: fatal: root(0): message file too big

Fix is easy. Set unlimited attachment size. How?

Gain root and run those commands:

postconf -e mailbox_size_limit=0
postconf -e message_size_limit=0

and then restart postfix with this command:

systemctl restart postfix

Cheers.

Andrzej

My method of backing up MySQL database under my Arch Linux server (coz I didn’t like the SloniuPL’s one).

Hi there!

I didn’t like SloniuPL’s method of backing up MySQL database so I wrote my own. Simpler. Nicer. Easier.

I wrote a script: /root/.bin/MySQL_BackUP.sh.

Which contains:

date &&
echo "Compressing /var/lib/mysql/ into a /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar file" &&
tar cfP /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar /var/lib/mysql/ &&
echo "What's the size of the /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar file?" &&
du -h /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar &&
date &&
echo "Compressing echo /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar into /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar.xz file." &&
xz -f --compress -9 /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar &&
date &&
echo "What's the size of the /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar.xz file?" &&
du -h /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar.xz &&
echo "Mailing the /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar.xz file to andrzejl@icsserver.loc." &&
date &&
echo "MySQL Database Backup `date +%m-%d-%Y`!" | /bin/mail -s "MySQL Database Backup `date +%m-%d-%Y`!" -a /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar.xz andrzejl@icsserver.loc &&
echo "Removing the /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar.xz file." &&
rm /home/andrzejl/MySQL_Database_Backup_`date +%m-%d-%Y`.tar.xz &&
echo "MySQL Database Backup finished!" &&
date

and it does exactly what it says on the box…

Wed Jun 11 07:14:45 IST 2014
Compressing /var/lib/mysql/ into a /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar file
What’s the size of the /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar file?
155M /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar
Wed Jun 11 07:14:52 IST 2014
Compressing echo /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar into /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar.xz file.
Wed Jun 11 07:17:01 IST 2014
What’s the size of the /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar.xz file?
7.1M /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar.xz
Mailing the /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar.xz file to andrzejl@icsserver.loc.
Wed Jun 11 07:17:02 IST 2014
Removing the /home/andrzejl/MySQL_Database_Backup_06-11-2014.tar.xz file.
MySQL Database Backup finished!
Wed Jun 11 07:17:02 IST 2014

AndrzejL_ArchLinux_MySQL_Database_BackUp_Method_001.png

AndrzejL_ArchLinux_MySQL_Database_BackUp_Method_002.png

AndrzejL_ArchLinux_MySQL_Database_BackUp_Method_003.png

And then I have edited my crontab so it looks like this:

0 */6 * * * /root/.bin/MySQL_BackUP.sh

This way I have a fresh and funky database snapshot every 6 hours…

After tiny modifications this script can be used to create a snapshot of any folder and send it to as many recipients and as often as You wish…

That’s what I call backup… and yes I am aware of the fact that it WOULD be best to stop the MySQL server before You will create a backup in case there is some writing going on*… and yes I am aware that mysqldump will create the .tar.gz file for me too… but this is a low profile home server and not some huge corporate database… You like it? Great. You want to use it? Copy script. Modify it. Use it. You have my blessing. I don’t give any warranties. It works for me. I don’t provide support so don’t even ask ;).

Cheers.

Andrzej

PS. * IF * the database is being written to while the backup starts it will not finish backing up:

tar: /var/lib/mysql/ib_logfile0: file changed as we read it

so broken / partially written database in the backup file _shouldn’t_ happen.

Block annoyances on Twit.tv using Adblock Plus.

Block annoyances on Twit.tv using Adblock Plus.

Depending on Your preferences use the filters below to block certain parts of the site.

1) Block background image:

twit.tv/sites/all/themes/plink/twit2011/img/page-back.jpg

2) Block header:

twit.tv##div#header.region-header.container-12.clearfix

3) Block entire Slideshow player + Schedule + Live Streams + Most recent episodes part:

twit.tv##div#preface-first.region-preface_first.container-12.clearfix

4) Block JUST the slideshow player plus its shadow and its controls:

twit.tv##div#views_slideshow_cycle_teaser_section_home_slideshow-block.views_slideshow_cycle_teaser_section

twit.tv##div.views-slideshow-controls-bottom.clear-block

twit.tv/sites/all/themes/plink/twit2011/img/player-shadow.png

5) Block Latest Posts:

twit.tv##div#homebox-block-panels_mini_latest_homebox.homebox-portlet.homebox-unclosable.clearfix.block.block-panels_mini.homebox-override-processed.homebox-processed

6) Block Twit Amazon:

twit.tv##div#homebox-block-panels_mini_twitpicks.homebox-portlet.homebox-draggable.homebox-unclosable.clearfix.block.block-panels_mini.homebox-override-processed.homebox-processed

7) Block footer:

twit.tv##div#footer.clearfix

Example:

I am using filters from the steps 4, 6 and 7:

Blocking_Parts_Of_Twit_TV.png

Cheers.

Andrzej