Yes, there is a reason, because previous Linux admin have made shell script to take backup, but it is not storing on remote machine, & that daily backup is storing on local machine, & manually we are taking backup to remote machine using "scp". I read rsync this is very good tool. but right now we wanted to copy those tar ball also to remote machine. So in that /backup/daily_backup directory it should find the newone & copy to different machine using scp. So I am struggling regarding this.
As you said, I made a shell script as below
file=$(ls -lt|head -1)
cp $file /backup
& ran the shell script, the out put as below
cp: cannot stat `total': No such file or directory
cp: cannot stat `12244': No such file or directory
it is finding 1st line which is the size of that directory & not able to copy.
for e.g plz see this below direcoty
$ ls -ltrh
-rw-r--r-- 1 linux linux 9.5M Apr 30 2010 boot.iso
-rw-rw-r-- 1 linux linux 2.3M Jul 13 16:53 testdisk-6.12.linux26.tar.bz2
-rw-rw-r-- 1 linux linux 157K Jul 18 16:35 Screenshot.jpg
-rw-rw-r-- 1 linux linux 46K Jul 18 16:42 hindu_god_ram.jpg
-rw-rw-r-- 1 linux linux 16K Jul 19 10:24 mdstat.doc
in above directory mdstat.doc is newone & I want to copy only that file, for that I made a shell script as below
file=$(ls -ltr|tail -1)
cp $file /backup
and gave the excecute permission & ran that shell script, but it is not working. plz see the below output
cp: invalid option -- w
Try `cp --help' for more information.
if I run as below from the terminal it is showing the new file.
$ls -ltr|tail -1
-rw-rw-r-- 1 linux linux 15872 Jul 19 10:24 mdstat.doc
but it is not copying when through shell script.
So plz tell me how can I do this.
I will be waiting for your kind reply.
Originally Posted by Tinkster
Is there a reason why you're not simply using rsync?