LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-28-2003, 11:23 PM   #1
stonelee
LQ Newbie
 
Registered: Sep 2003
Posts: 2

Rep: Reputation: 0
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
 
Old 09-29-2003, 03:18 AM   #2
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Maybe you want to use Perl instead. It combines the powers of grep, sed, and sh (bash)
 
Old 09-29-2003, 09:47 AM   #3
argh2005
Member
 
Registered: Aug 2003
Distribution: redhat 9.0
Posts: 37

Rep: Reputation: 15
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...------------
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting - help needed jonhewer Linux - Newbie 54 09-09-2005 02:58 PM
bash scripting --- some help needed rajsharma Linux - Software 1 09-09-2005 02:49 AM
scripting help Abe_the_Man Linux - General 1 11-03-2004 05:30 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM
Shell scripting and background processes - help needed. trafalgar Programming 3 06-08-2003 09:15 AM


All times are GMT -5. The time now is 11:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration