LinuxQuestions.org

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

rajsharma 09-09-2005 12:42 AM

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

acid_kewpie 09-09-2005 02:49 AM

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...


All times are GMT -5. The time now is 09:30 AM.