back script

vi /usr/bin/back



#!/bin/bash

if ! [ -f $1 ]; then
   echo "File '$1' does not exist!"
   exit 1
fi

if [ -f $1.$(date +%d%m%Y) ]; then
   counter=2
   while [ -f $1.$(date +%d%m%Y)_$counter ]; do
      let counter=$counter+1
   done
   cp $1 $1.$(date +%d%m%Y)_$counter
else
   cp $1 $1.$(date +%d%m%Y)
fi

 

 

This entry was posted in Linux. Bookmark the permalink.