A Sample Script

team bbl


The following is a sample script. It backs up selected files from a directory:

 #!/bin/bash # Script name: project1_backup # Description: Backs up project files into a subdirectory for file in proj1* do     fback=project1/$file.bak     if [ -f $fback ]       then          if [ $fback -nt $file ]             then                cp $file $fback                echo `date` $file backed up >> backup.log          fi     else          cp $file $fback          echo `date` $file backed up >> backup.log     fi done 

The script iterates through a list of filenames that begin with proj1. It checks whether the current file is newer than the existing backup file. If so, it copies the current file into the backup directory, giving it a .bak extension. Also, any current file that has not yet been backed up is copied into the backup directory.

    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net