Automate tasks in Windows and Linux

Why to automate

Automation is saving time and is best way to protect yourself from forgetting. I use also automation of small tasks as a delegation. I delegate some of my tasks to my PC.

The advantages of are:

  • The PC never forgets
  • The PC is never wrong :) - only human programs and algorithms do.
  • I can do something else while my tedious or boring tasks are done
  • Huge tasks can be done effortlessly - Once we had to convert more than 10000 pics, to do some changes, to rename the file according to some needs and to categorize them. Time for the program: 4 hours and 2 hours tests. The processing took about 1 hour and 1 hour to verify the results. I can't imagine if we had to do it manually what time we had to spent and the errors.
  • You can reuse the automated tasks

Windows

You can use Task Scheduler(example for windows 7 - it may also be called 'Scheduled Tasks' you can find it located in the Control Panel.):

  • Starting

  • Create new task

After that is really straightforward:

  • first you need to give the "trigger" - when to start the task:
  • based on time frequency
  • event - computer start, login etc
  • one time - you can run it manually later (select the task and start it from the context menu);
  • next is to set up the program that will be run:
  • start a program - you can put a command and parameters - for example run music every hours and give as parameters this song.
  • send a mail
  • display a message

Linux

You can use crontab(depending on the distribution - in this example I'm using Ubuntu 14):

  • Installation
sudo apt-get update
sudo apt-get install cron
  • set up
  • create new job(per user) by
crontab -e [username]
  • add tasks
    If the command runs properly, a text editor will appear. Now you can add your commands to the crontab file. To run python script every five minutes:

*/5 * * * * python /home/user/test.py
*/5 * * * * /home/user/test.sh

  • save the text file - depending on the text editor that is used - id could be ctrl + X and then Y or something else. The is to read the instructions.

Cron information

Read more about it on the following pages: Wikipedia: crontab

cron expressions

.---------------- minute (0 - 59) 
|  .------------- hour (0 - 23)
|  |  .---------- day of month (1 - 31)
|  |  |  .------- month (1 - 12) OR jan,feb,mar,
|  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue..
|  |  |  |  |
*  *  *  *  *  command to be executed

Related Article