Bash question
Alan Jackson
ajackson
Mon May 17 11:59:37 PDT 2004
On Fri, 20 Feb 2004 18:41:28 -0500
Bruce Marshall <bmarsh at bmarsh.com> wrote:
> I'm trying to write a bash script that uses the 'find' command. I want to
> pass it a wild-card argument like *.jpg
>
> The argument always does the file expansion thing like it is supposed to....
> but is there a way to pass such an argument without having the expansion take
> place?
>
> Done my homework, reading the manual, trying various things out.... no joy.
>
Here's a script I run that does that... in fact it does a number of stupid find
tricks...
I ran one today where I wanted to look for all files modified around
December 1, it looked like find . \( -mtime +75 -a -mtime -85 \) -print
#!/bin/sh
# Do backups using tar
# first clean up files that should not be backed up (like deleted mail)
# then create a list of files newer than the last backup
# save the current time by touching a file
# tar the listed file to a compressed tar file
# Clean up extraneous files
echo "Cleaning up mail"
find /home/ajackson/Mail \( -name ',[0-9]*' \) -ls -exec rm {} \;
rm ~ajackson/.bak
# first find all files newer than the .last_backup file
# that are not directories
# Do not look in mounted filesystems (this prevents looking at the
# DOS partitions
echo "Running find command"
/bin/rm -f /tmp/backups
/bin/rm -f /home/ajackson/.maildir/new/*
##find / -mount -newer /.last_backups ! -type d ! -name "backtar.gz" \( -regex "^/var/*" -o -regex "^/usr/local/*" -o -regex "^/opt/*" \) -a -prune -fprint /tmp/backups_all
#find / \( -regex "^/var/*" -o -regex "^/usr/local/*" -o -regex "^/opt/*" \) -a -prune -o -mount -newer /.last_backups ! -type d ! -name "backtar.gz" -fprint /tmp/backups_all
find /etc -newer /.last_backups ! -type d ! -name "backtar.gz" -fprint /tmp/backups_all_etc
find /home/ajackson -newer /.last_backups ! -type d ! -name "backtar.gz" ! -name "*.wav" ! -name "*.mp3" ! -name "*.ogg" ! -name "*.jpg" ! -name "*.gif" -fprint /tmp/backups_all_home
cat /tmp/backups_all_etc /tmp/backups_all_home > /tmp/backups_all
# remove stuff from file that doesn't get backed up
cat /tmp/backups_all | grep -i -v -E 'cache' | grep -i -v 'glameswap' | grep -i -v 'tif' | grep -v 'trash' | grep -v 'backup' | grep -v 'queue' | grep -v 'thumbnails' > /tmp/backups
# reset .last_backups file
touch /.last_backups
# Create tar file
tar -cvzf /backtar.gz --files-from /tmp/backups
cp /backtar.gz /archive/backups/`date +%y%m%d:%H%M`.gz
echo "Tar file creation done. File is "
echo "`ls -als /backtar.gz`"
echo "File copied to /archive/backups/`date +%y%m%d:%H%M`.gz "
--
-----------------------------------------------------------------------
| Alan K. Jackson | To see a World in a Grain of Sand |
| alan at ajackson.org | And a Heaven in a Wild Flower, |
| www.ajackson.org | Hold Infinity in the palm of your hand |
| Houston, Texas | And Eternity in an hour. - Blake |
-----------------------------------------------------------------------
More information about the Linux-users
mailing list