Schedule Tasks in Linux with Ease – Kcron

When I first started using Linux, one of the most daunting tasks was creating crontabs to automate processes. For example, one might want to rotate apache logs (done automatically now by most distros) or perhaps pull info out of those logs, paste them to a file, and send said file to the webmaster. Now this wouldn’t be feasible to do by hand daily and that is where crontabs come in. Just like scheduled tasks in Windows, crontabs allow you to run a process at a given time. Unlike Windows though, you have ultimate control over the task. Nowadays, things are much easier by using a GUI such as Webmin, pycron, or Crontooie (if you’re a MAC user). The great thing is that KDE contains a handy tool to create and manage your Crontabs. You can disable or enable them straight from an easy to understand and control GUI. Today, we’re going to take a look at how to setup a simple crontab using Kcron.

Let’s start off by seeing if the cron daemon is even running on your system. Open up a Konsole or Shell and type the following:

ps aux | grep crond

If there is output similar to that in the screenshot, we’re in business because the cron daemon is running. If not, restart cron by typing: ./usr/sbin/crond (may vary by your distro…if you need help, let me know in comments section).

I use PCLinuxOS for my Linux desktop. You can find Kcron by navigating to Kmenu >> Configuration >> Other and selecting it.

Kcron will open and you’ll see the default menu. You should see two categories in the main area: “Tasks” and “Variables”

Variables identifies items you can set to help with your task scheduling. For instance, say you want a custom variable to stand for one users’ desktop…so you’d set the PATH variable to their /desktop. Now remember, when you set this variable, Kcron will use in in lieu of the normal path. There are also other variables you can set. There is extended help on variables in the Kcron handbook. For now though, let’s look at the other item on our list…and, subsequently, the meat and potatoes of what Kcron does. Tasks.

With Tasks, you setup the command you want to execute. This can be something simple like mailing you out a synopsis of logs or even nmap penetration scans. It’s up to you what you want to do with it. We’ll start with something extemely simple to show how Kcron works.

Highlight “Tasks” then select the Edit menu and choose “New”

This should bring up a new task menu. Glancing over this menu, you can see that things are pretty self explanatory. You have dates and times, options for repeating weekly, monthly, or daily. Basically, it’s spelled out for you. This is much easier than the old way of doing crontabs where one had to enter into the crontab file and place asterisk after asterisk and remember what each one of those asterisks meant and try to keep one’s place with all the asterisks to remember which placeholder to flag to enable the cron. Now, it’s as easy as point and click.

For training purposes, we’ll setup a task that should already be setup by default in most distributions…we’ll schedule an index update for file location purposes. Just like windows uses indexing service, Linux has a built in ‘indexer’ (term is used loosely here because it is really a database of your filesystem) that we can populate and update…which you’ll want to do, especially if you install many updates. As stated earlier, this task should already be scheduled in most distributions by default. Let’s practice though by setting it up to run. Looking at the window we opened in the previous paragraph, enter in the comments “My First Linux Task – Updatedb”. Next, for the command, enter “/usr/sbin/updatedb”. Now choose when you want to run it. I chose every Wednesday of each and every month at 9:30 AM. After I set this, I choose “Ok”. Now we must save the task.

Go to File >> Save and now you’re in business. Never forget to save AFTER you’ve altered the task, otherwise your changes will go right out the window.

You can get more creative and add your own custom paths or mail addresses by using variables. As you can see in the screenshot above, I’ve input my mail address in case I want my cron output mailed to me.

Remember, as long as you know the command that you want to do, you just place it in the blank, schedule it, make sure the enable box is checked, and save. For instance, say you want to backup your files for linux to your windows share. You could use the following command to back things up into a handy tar archive:

cd /home/devnet;tar -cvf – * | tar -C /mnt/windows/share/backup -xv

The only limitation is knowledge. If ever you are in doubt of what a certain function entails, open up the Kcron handbook. It might not answer your question but you can get pointed in the right direction. Another good resource would be the developers. If there is one thing I know about KDE its that the developers are always willing answer a rogue question about the functionality of their application.

You can find both the programmers/developers of Kcron and the Kcron handbook under the help menu. Please remember that developers can answer questions about the application but are not there to come up with custom commands for you to use in Kcron…you’ll have to do that legwork yourself! Hopefully, this will get you started scheduling your own backups and tasks.

This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.

Go to File >> Save and now you're in business. Never forget to save AFTER you've altered the task, otherwise your changes will go right out the window.
  • http://www.visualcron.com Brian

    In windows I recommend using VisualCron (http://www.visualcron.com)as task scheduler instead of the built in.

    regards,

    Brian

  • Gerard Reitsma

    Hi Brian, I’m using PCLinuxOS 2007.
    Everything goes right in Kcron. Even the saving.
    But nothing happens on the time it has to begin working. Crond is on, Anacron too (services).

    Can you help me?

    Gerard.

  • /dev/null Kos Ivantsov

    if you want to run X application by the means of kcron, you have to be logged in into X-session, and you have to export your $Xauthority and $DISPLAY.
    to do that, add
    —–
    export XAUTHORITY=~/.Xauthority;export DISPLAY=:0;your_app_that_you_need_to_run
    —–
    into the line “program” of you task