LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Scripting help needed. (https://www.linuxquestions.org/questions/linux-software-2/scripting-help-needed-98082/)

stonelee 09-28-2003 11:23 PM

Scripting help needed.
 
I am having difficulties writing a bash script to compare files in one directory to a second directory. If the file in the second directory is newer, delete the file from the first directory and copy the file from the second directory to the first. To add to difficulty, the file names have a base with numbers. The numbers are revision identifiers. For example,

directory 1 ... file thefile-0.1.3.0 compare to thefile-0.1.3.1. The second file is newer. Delete the first file and copy the new file to directory 1.

Please help...

Thanks,
stonelee

yapp 09-29-2003 03:18 AM

Maybe you want to use Perl instead. It combines the powers of grep, sed, and sh (bash)

argh2005 09-29-2003 09:47 AM

Okie, I find this script in a tutorial about bash's scripting. You could modify this a bit and you should be able to do what you need as you describe above.

#!/bin/bash

# Backs up all files in current directory modified within last 24 hours
#+ in a "tarball" (tarred and gzipped file).

BACKUPFILE=backup
archive=${1:-$BACKUPFILE}
# If no backup-archive filename specified on command line,
#+ it will default to "backup.tar.gz."

tar cvf - `find . -mtime -1 -type f -print` > $archive.tar
gzip $archive.tar
echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"."


# Stephane Chazelas points out that the above code will fail
#+ if there are too many files found
#+ or if any filenames contain blank characters.

# He suggests the following alternatives:
# -------------------------------------------------------------------
# find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar"
# using the GNU version of "find".


# find . -mtime -1 -type f -exec tar rvf "$archive.tar" '{}' \;
# portable to other UNIX flavors, but much slower.
# -------------------------------------------------------------------


exit 0



--------hope this is helpful...------------


All times are GMT -5. The time now is 07:10 AM.