home

Quickies, by Andrea Olivato

text

Adding a line to Crontab from bash script

How to insert a new line to existing crontab using a simple bash script


#!/bin/bash

# Set up the new line you want to insert
$newLine="* */5 * * * do something every 5 hours";

# Copy existing crontab to temp file
crontab -l > /tmp/cron

# Adding desired line at the end of the temp file
echo $newLine >> /tmp/tmpcron

# Installing new crontab
crontab -e /tmp/cron

# Removing temp file
rm /tmp/cron

3 years ago

May 19, 2009
Comments (View)
blog comments powered by Disqus