Thursday, March 11, 2010

Moving files with Script

#! /bin/sh
echo "# +-----------------------------------------------------------------------"
echo "# | Script ID:     backup_output.sh"
echo "# | Purpose:       This script moves the daily output files to a backup "
echo "# |                directory and cleans out the previous day's files"
echo "# +-----------------------------------------------------------------------"
echo " "
echo "# +-----------------------------------------------------------------------"
echo "# | clean out backup directory before proceeding to copy                  "
echo "# +-----------------------------------------------------------------------"

cd /xyz/out_backup                                            # Change to output backup
echo "Directory: "; pwd                                       # Display on screen

for EXTENSION in txt TXT csv CSV xls XLS doc DOC              # For each one in this list,
do                                                            # do the following:
  echo $EXTENSION                                             # Display the extension.
  if [ -e *.$EXTENSION ];                                     # if a file exists like that...
     then ls *.$EXTENSION |wc -l                              # then display the count
          rm *.$EXTENSION                                     # delete those files
     else echo '    -- not found'                             # otherwise, display 'not found'  
  fi                                                         
done                                                         

echo "Directory: "; pwd                                       # Display on screen
echo "Anything left?"
ls

echo "# +-----------------------------------------------------------------------"  
echo "# | copy files only if they exists                                        "
echo "# +-----------------------------------------------------------------------"  

cd /xyz/output                                                # Change to output directory
echo "Directory: "; pwd                                       # Display on screen

for EXTENSION in txt TXT csv CSV xls XLS doc DOC              # For each one in this list,
do                                                            # do the following:
  echo $EXTENSION                                             # Display the extension.
  if [ -e *.$EXTENSION ];                                     # if a file exists like that...
     then ls *.$EXTENSION |wc -l                              # then display the count
          mv *.$EXTENSION /xyz/out_backup                     # move those files to the backup dir
     else echo '    -- not found'                             # otherwise, display 'not found'  
  fi                                                         
done                                                         

echo "Directory: "; pwd                                       # Display on screen
echo "Anything left?"
ls

No comments:

Post a Comment