Linux - SoftwareThis 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.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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:
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.
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:
for file in $(cat /blah/something/backups)
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
chown backup:backup /usr/local/backup -R
something like that will suffice maybe?
I really hope this is a real question and not homework...