# Cron Job

**URL:** <https://forums.suse.com/t/cron-job/22520>\
**Category:** SLES Configure-Administer\
**Created:** [April 18, 2012, 4:03am UTC](https://forums.suse.com/t/cron-job/22520 "2012-04-18T04:03:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![carnold6](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@carnold6](https://forums.suse.com/u/carnold6)\
**Post date:** [April 18, 2012, 4:03am UTC](https://forums.suse.com/t/cron-job/22520/1 "2012-04-18T04:03:03Z")

</div>

SLES11 SP2. I need to create a cron job that will run a rsync backup nightly. I have a script:

[code]#!/bin/bash

#Script to backup ELC’s Share folder to off-site NAS through VPN (Tek-Nerds).  
#Specify the mount point here  
mount\_point=’/mnt/backup’

echo “####”  
echo “”  
#Check to see if the NAS is mounted and if not mount it.  
if ! mountpoint -q ${mount\_point}/; then  
echo “Mounting the NAS”  
echo “Mount point is ${mount\_point}”  
if ! mount ${mount\_point}; then  
echo “An error was returned by the mount command!”  
exit 5  
else echo “Mounted successfully”;  
else echo “${mount\_point} is already mounted”;  
fi

#Target must be mounted at this point, or job dies  
if ! mountpoint -q ${mount\_point}/; then  
echo “Mounting failed! Cannot run backup without the backup mounted!”  
exit 1  
fi

echo “Preparing to transfer files using rsync”

#Use current year to create new backup directory each year  
#current\_year=‘date +%Y’

#Specify mount point followed by the path to the bakup directory, finish with current year  
#Would like to add month and date  
#backup\_path=${mount\_point}’/EdensLandCorp/’${current\_year}  
#echo “Backup directory is ${backup\_path}”

echo "starting backup of /Share/_…"  
rsync --verbose --progress --stats --compress --recursive --times --perms --links --delete /Share/_ /mnt/backup 2\>&1 | tee /mnt/backup/elc\_backup.txt[/code]

but i am not ready to use it yet, as i need to figure out the mount\_point in the script. I mount a nas to /mnt/backup and have rsync backup to that mount point. What i would like now is to know how to create a cron job that runs this command, nightly and 7:00pm:

```auto
rsync --verbose --progress --stats --compress --recursive --times --perms --links --delete /Share/* /mnt/backup 2>&1 | tee /mnt/backup/elc_backup.txt
```

Can anyone help me with this?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [April 18, 2012, 4:09am UTC](https://forums.suse.com/t/cron-job/22520/2 "2012-04-18T04:09:51Z")

</div>

On Wed, 18 Apr 2012 01:04:01 +0000, carnold6 wrote:  
[color=blue]

> What i would like now is to know how to create a cron job that runs this  
> command, nightly and 7:00pm[/color]

Easiest way would be to create a cron entry using ‘crontab -e’ as root:

# crontab -e

The format of the crontab lines is documented in ‘man 5 crontab’ - it’s a  
fairly straightforward format:

0 19 \* \* \* commandtorunhere -withparameters -likethis

I’d probably put the command to run in a shell script and call the shell  
script from crontab instead - you’ll want to make sure to use absolute  
paths uniformly.

Jim

–  
Jim Henderson, CNA6, CDE, CNI, LPIC-1, CLA10, CLP10  
Novell Knowledge Partner
