LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-09-2005, 12:42 AM   #1
rajsharma
LQ Newbie
 
Registered: Sep 2005
Posts: 1

Rep: Reputation: 0
bash scripting --- some help needed


Hi all,

I want to write a bash script for some task that will save a lot of time.
Basically given the following file format:

==================================================
The following list of files implement this module.

List of files:
... //repository/usr/local/file1
... //repository/usr/local/dir/file2
... //repository/usr/tmp/file3

some other description.
===================================================

I need to read this file and create a backup of each listed file. But I am having a
hard time reading file path and names. In the above file, === line is not
present in the file (just here for clarity). So in the above example, I need to create
the following backups in /usr/local/backup directory:
/usr/local/file1 -> /usr/local/backup/usr/local/file1.bk
/usr/local/dir/file2 -> /usr/local/backup/usr/local/dir/file2.bk
/usr/tmp/file3 -> /usr/local/backup/usr/tmp/file3.bk

After creating backups, I need to change the group of actual files to "backedUp".

I also want to echo proper messages. So I copy a file, if it is successful (based on the error return code in bash), I want to echo "created backup of this file to this file". If any error occurs in between, I need to roll back all changes. So the entire operation is atomic.

I also want some way to verify output in the end.

Any help on this is highly appreciated.

Raj
 
Old 09-09-2005, 02:49 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
so where are you actually stuck? (those ==='s are not for clarity btw..!) if you have this simple list file then accessing each line is just down to the contents of a for loop:

Code:
for file in $(cat /blah/something/backups)
do
  echo backing up $file to /usr/local/backup/$file.bk
  cp $file /usr/local/backup/$file.bk
  if [$? -ne 0 ] then
    echo error in last backup attempt
  fi
done
chown backup:backup /usr/local/backup -R
something like that will suffice maybe?

I really hope this is a real question and not homework...
 
  


Reply



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 Gunslinger_ROL Programming 5 09-28-2004 11:37 AM
Scripting help needed. stonelee Linux - Software 2 09-29-2003 09:47 AM
HELP with BASH scripting atwah Linux - Newbie 6 09-09-2003 01:10 AM
bash scripting -=MaGo=- Programming 16 08-30-2003 07:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration