Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Help With Script, I could do with a bit of help...
benb3342
post Nov 18 2003, 11:34 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 2
Joined: 18-November 03
Member No.: 1,818



#!/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)
Go to the top of the page
 
+Quote Post
hughesjr
post Nov 18 2003, 05:26 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



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


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
benb3342
post Nov 19 2003, 09:16 AM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 2
Joined: 18-November 03
Member No.: 1,818



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 21st October 2017 - 09:05 AM