Need help writing a shell script/cron job

Discussion in 'Programming/Scripts' started by sc30317, Sep 15, 2009.

  1. sc30317

    sc30317 New Member

    Here is my issue:

    I have to write a shell script that archives pictures stored in a directory.

    within my /home/pictures directory, jpegs get saved.

    Once the folder gets large enough (100MB), I would like to make a tar.gz archive all the files located in the directory, and move them to /home/archives.

    How would I go about writing a shell script/cron job to perform this?
     
  2. sc30317

    sc30317 New Member

    here is what I have so far:
    Code:
    #!/bin/bash
    # Backup Script
    
    echo "\nWelcome to the backup script\n"
    cd /home/images
    
    if [$du -h /home/images] >= 100MB ; then
       tar -pczf `date`.tar.gz /home/pictures/backup
    fi
    
    exit 0;
    
    This doesn't work right.
     
  3. Franz

    Franz Member

    Try this



    Code:
    #!/bin/bash
    # Backup Script
    
    echo "\nWelcome to the backup script\n"
    path="/home/images"
    
    if [ `du -ms $path` > 1000 ] ; then
            find $path > /tmp/list.txt
            tar -T /tmp/list.txt -pczf `date`.tar.gz
            for i in `cat /tmp/list.txt`; do
                    rm -rf $i
            done
    fi
    
    exit 0;
     

Share This Page