Solving IT problems and building solutions

  • Wednesday, November 7, 2012

    Useful Cron Alternatives For Linux

    Anacron is a periodic command scheduler just like cron. The only difference is that it does not need your computer to be always running. You can schedule your task to run at any time. When your computer is off, the task will be executed the next time you turn the computer on.
    To get started, simply install anacron in your system. It is available in most package managers. Use the following command to install in Ubuntu:
    sudo apt-get install anacron
    Anacron works similar to cron. You can add your job to the /etc/anacrontab file.
    The syntax to add a job is
    period   delay-after-computer-start   job-identifier   command
    For example, to run a backup script everyday, you can add the following command:
    1   15    cron.daily     /bin/sh /home/damien/backup.sh
    The disadvantage of anacron is that it only deals with tasks on a daily, weekly or monthly schedule. You can’t use it for a hourly or minutes schedule.
    Fcron is the best of both cron and anacron. It doesn’t require your computer to be running 24×7, and it can work with tasks on an hourly or minute basis.
    The only way to install Fcron is to download the source file and compile it yourself.
    1. Download the source file here.
    2. Extract the archive. Open a terminal and change the filepath to the extracted archive folder.
    3. Run the following commands:
    ./configure
    make
    sudo make install
    It will ask you a few questions during the installation and you can safely answer “y” (yes) for all of them.
    To start creating a fcron job, simply type fcron -e in the terminal.
    The syntax for fcron is similar to cron:
    minute  hour  day-of-month  month  day-of-week  command-to-be-executed
    and it comes with more options than cron, such as setting up a task to run between a time range.
    For those who prefer a GUI, you can check out fcronq
    Hcron is relatively unknown, but that does not make it less useful. In fact, it comes with several features that make it unique. For example, you can easily label and organize your cron type jobs, manage a network of computers and your users’ crontab files, beck up easily, and version control your cron type jobs. The only drawback is that it has not been updated since 2010.
    To install hcron, download the .deb file and install it in your system. For distro that are using rpm, you can easilyconvert the deb file to rpm.
    Hcron stores each event as a plain text file. To get started, simply create a text file with the command:
    hcron-event /path/to/event-file.txt
    In the text editor that opens, you can fill in the details of the event.
    There are many more things that you can do with hcron and it is advisable to download the user guide to have a better understanding of how it works.
    Jobber is a task scheduler written in GO and is a more powerful tool than cron. It features job execution history with status, controlling whether and when a job is run again after it fails and getting notified on each failed run or only about jobs that were disabled due to repeated failures.
    To install Jobber, you have to make sure that GO is installed in your system. Next, type the commands:
    cd /path/to/your/go/workspace
    go get github.com/dshearer/jobber
    make -C src/github.com/dshearer/jobber
    After the installation, start Jobber with the command:
    sudo /usr/local/sbin/jobberd start
    To create jobs, create a file named “.jobber” in your home directory and add the job in the following format:
    - name: #Enter the job name here
      cmd: #the command to run
      time: #as the same as cron format
      onError: #Stop | Backoff | Continue
      notifyOnError: #false | true
      notifyOnFailure: #false | true
    As you can see from the format, it allows you to define the actions to take when it has errors (“Stop”, “Backoff” or “Continue”) and whether it should notify you when it fails.
    Once you have updated the job list, use jobber reload to get Jobber to reload the new list.
    At any time, you can use jobber log to see a list of recent runs of any jobs.
    Cron is widely available and easy to use, but when it doesn’t work as you require, you might be better off using a replacement app. The cron alternatives above are more powerful than cron and should fulfill your needs. If you know of other cron replacement apps that are not mentioned above, feel free to let us know in the comments below.

    No comments:

    Post a Comment