This is the small script I have written for this task , but when I execute it instead of files defined in system1-dr.txt getting copied system1-dr.txt file get copied.
below is the script
cat script1
for i in /users/jack/system1-dr.txt
do
sudo cp $i /users/jack/DRbep01
done
cd /users/jack/DRbep01
tar-cvf system1.tar *
scp system1.tar backupserver:/users/jack/stsyem1
Could you please guide me in this and how more sophiscated script can I make it..?
$cat script1
while read i
do
sudo cp $i /users/jack/DRbep01
done</users/jack/system1-dr.txt
cd /users/jack/DRbep01
tar-cvf system1.tar *
scp system1.tar backupserver:/users/jack/stsyem1
Though the previous post is absolutely correct, we here at unix.com are more in favor of pamu's solution for it avoids the use of a not necessary cat command
Thanks, your while loop works.
But could you all please tell two things
How to put command in this while loop or script which will
-rename /etc/default/passwd to passwd-default as there are two file named passwd on system and other is under /etc/passwd
-secondly this /etc/shadow file is having r-- --- --- permission so first I need to change its permission to say 755 and then copy to /users/jack/DRbep01
It will be great help to me to know this, I am beginner in scripting,I will get idea by your suggestions.
Since you are silent and after I will not have the time to explain anymore so look at the following command I just typed for you and meditate: It keeps the perms, timestamps etc....
ant:/home/vbe/admin/shell/tests $ ll
total 30
-rw-rw-r-- 1 vbe bin 137 Jan 30 17:17 infile
-rw-rw-r-- 1 vbe bin 14336 Jan 30 17:20 titi
ant:/home/vbe/admin/shell/tests $ more infile
./etc/passwd
./etc/shadow
./etc/group
./etc/vfstab
./etc/profile
./etc/default/cron
./etc/default/fs
./etc/shells
./etc/default/security
ant:/home/vbe/admin/shell/tests $ cd /
ant:/ $ cpio -ocv </home/vbe/admin/shell/tests/infile >/home/vbe/admin/shell/tests/titi
etc/passwd
etc/shadow
etc/group
"etc/vfstab": No such file or directory
Cannot stat <etc/vfstab>.
etc/profile
etc/default/cron
etc/default/fs
etc/shells
etc/default/security
28 blocks
ant:/ $ cd ~/admin/shell/tests
ant:/home/vbe/admin/shell/tests $ ll
total 30
-rw-rw-r-- 1 vbe bin 137 Jan 30 17:17 infile
-rw-rw-r-- 1 vbe bin 14336 Jan 30 17:31 titi
ant:/home/vbe/admin/shell/tests $ cpio -cit <titi
etc/passwd
etc/shadow
etc/group
etc/profile
etc/default/cron
etc/default/fs
etc/shells
etc/default/security
28 blocks
ant:/home/vbe/admin/shell/tests $ cpio -icdmv < titi
etc/passwd
etc/shadow
etc/group
etc/profile
etc/default/cron
etc/default/fs
etc/shells
etc/default/security
28 blocks
ant:/home/vbe/admin/shell/tests $ ll
total 32
drwxr-xr-x 3 root sys 1024 Jan 30 17:33 etc
-rw-rw-r-- 1 vbe bin 137 Jan 30 17:17 infile
-rw-rw-r-- 1 vbe bin 14336 Jan 30 17:31 titi
ant:/home/vbe/admin/shell/tests $ cd etc
ant:/home/vbe/admin/shell/tests/etc $ ll
total 28
drwxr-xr-x 2 root root 96 Jan 30 17:33 default
-r--rw-r-- 1 bin bin 4509 Jul 8 2011 group
-r--r--r-- 1 root sys 2775 Jun 23 2011 passwd
-r--r--r-- 1 bin bin 2871 Jun 2 2009 profile
-r-------- 1 root sys 1585 Jun 23 2011 shadow
-rw-rw-r-- 1 root bin 159 Sep 2 2008 shells
ant:/home/vbe/admin/shell/tests/etc $ cd default
ant:/home/vbe/admin/shell/tests/etc/default $ ll
total 8
-r--r--r-- 1 root root 1120 Aug 24 2006 cron
-r--r--r-- 1 bin bin 11 Nov 15 2000 fs
-rw-r----- 1 root bin 232 May 7 2010 security
ant:/home/vbe/admin/shell/tests/etc/default $
the commands were passed with a sudo root...
As you can see I created an archive named titi using a file called infile...
Well if you looked at what I did:
1) Preamble you have to be root somehow ( I used sudo...)
2) To not mix the files, you keep the file structure ( tree...)
3) I did all you wanted with one command : cpio
a - It can create an archive: titi
b - Using correct options it keeps all you need to be a true archive: ownership, perms, timestamps...
c - you can see the content
d - you can restore its content
So start by reading the man pages of cpio and look carefully what I produced
UNIX has to be seen as a great toolbox, with so many tools... why try to invent new ones when one existing does the job?
--- Addendum---
Thread closed for the initial question/issues has been solved, and the topic changed...