Help - Search - Members - Calendar
Full Version: Help With Script
Linuxhelp > Support > Technical Support
benb3342
#!/bin/bash
find /var/spool/mmsmtp/quarantine -mtime +28 -exec mv '{}' /var/spool/mmsmtp/tmp/ ';'
tar -cf var/spool/mmsmtp/old/old_mail-`date +%Y%m%d`.tar var/spool/mmsmtp/tmp/*
rm -f /var/spool/mmsmtp/tmp/*




OK what simple thing have I missed? smile.gif

Desription of what I am _trying_ to do:
In the first line I am trying to find all files 28 days old or older and move them to the tmp folder.
Next I want to tar them, and put the tar in old.
Then I want to delete everything in the tmo folder.

Also how can I make the locations and file name variables?


Thanks for your help.

Ben
(big newbie)
hughesjr
Try this ... I am using version 1.13.25 of GNU tar (it has the --remove-files option ... it only removes files on sucessful completion of add/update command).

The script will create the tarfile if it doesn't exist ... or add to the file if it does exist. If you also want to gzip the file afterwords, then remove the # from gzip $tarfile as the last line and from:
#if [ -f "$tarfile".gz ]; then
# #this file has already been zipped ... unzip it
# gunzip "$tarfile".gz
#fi


CODE
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
movepath=/var/spool/mmsmtp/quarantine
tmppath=/tmp/move
tarfile=/var/spool/mmsmtp/old/old_mail-`date +%Y%m%d`.tar

if [ ! -d $tmppath ]; then
mkdir $tmppath
fi

find $movepath -name '*' -type f -mtime +28 -exec mv {} $tmppath \;

cd $tmppath
listfiles=`ls $tmppath`
if [ x"$listfiles" = x ]; then
 echo "There are no files!"
 exit 0
else
 #if [ -f "$tarfile".gz ]; then
 # #this file has already been zipped ... unzip it
 # gunzip "$tarfile".gz
 #fi
  if [ -f $tarfile ]; then
    tar --remove-files -Prvf $tarfile $listfiles
  else
    tar --remove-files -Pcvf $tarfile $listfiles
  fi
  cd /tmp
  tmpfiles=`ls $tmppath`
  if [ x"$tmpfiles" = x ]; then
     rm -rf $tmppath
  else
    echo "There are files in the Temp directory!"
  fi
fi
#gzip $tarfile
benb3342
biggrin.gif

Brilliant thanks.

Will try it out tomorrow.

Linux is getting much easier, and much more impressive the more I use it.

Thanks again,

Ben
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.