overwriting existing files with scp.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting overwriting existing files with scp.
# 1  
Old 08-12-2010
overwriting existing files with scp.

Ok. I am using one cluster to remotely write into another cluster. I can scp to copy files from cluste1 to cluster2, however, I need to copy a file that already exists in cluster 2 and replace it with the new file. I was thinking I could either remove the file in cluster 2 (which I don't know how to do) then use scp to copy the new file over, or use some variation of scp to overwrite the existing file in cluster2 with the new file in cluster1 (which I don't know how to do).

So lets say I do a
Code:
 scp directory/file1 user@host:directory/file1

but file2 in user@host already exists.

---------- Post updated at 10:39 PM ---------- Previous update was at 09:23 PM ----------

Ok. I'm trying to do this another way. If I can execute a script from cluster one to cluster 2 then I won't need to scp the file. I can seem to get it to work. This is what I have so far.

Code:
sh samplescript2.sh

samplescript2.sh has the following code

Code:
ssh user@host2 /bin/bash < /directory/samplescript.sh

samplescript.sh has the following code
Code:
cd /home/user/directory

yy=`date +%Y`
mm=`date +%m`
dd=`date +%d`

echo "Today is : $yy $mm $dd"

echo `pwd`

# Edit latest.txt file
  echo "${yy}${mm}${dd}00"            >latest.txt

When I execute the script I can see the date and the directory but nothing happens to the latest.txt file. Any ideas?
# 2  
Old 08-12-2010
I can not reproduce that scp problem. scp overwrites any file that exists. I could also not find any option in it's man page to force overwriting or similar.

Maybe checkout this behaviour on other boxes of yours.
# 3  
Old 08-12-2010
Figure it out

Ok. It worked. I simply made a mistake with my directory address in the script. Both options worked. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Filesystems, Disks and Memory

Slow copy (cp) performance when overwriting files

I have a lot of binary files I need to copy to a folder. The folder is already filled with files of the same name. Copying on top of the old files takes MUCH longer than if I were to delete the old files then copy the new files to the now-empty folder. This result is specific to one system -... (3 Replies)
Discussion started by: ces55
3 Replies

3. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

4. Shell Programming and Scripting

Copy files from multiple directories into one directory without overwriting them

I have several directories and all those directories have .dat files in them. I want to copy all those .dat files to one directory say "collected_directory" The problem is I don't want to overwrite files. So, if two file names match, I don't want the old file to be overwritten with a new one. ... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. Shell Programming and Scripting

Replacing the existing files only

Hey, Can someone pls give me an idea on how to write a shell script for the below requirement. I am generating lot of .txt files in a unix directory through a etl tool, now I need to write a shell script which will move these files to another directory(\abc\xyz\source), but in the... (2 Replies)
Discussion started by: shruthidwh
2 Replies

6. Shell Programming and Scripting

copy files using scp without overwriting

Hi, i need to use "scp" to copy a file without overwriting the same in destinations. any suggestion? thanks Sivaji (3 Replies)
Discussion started by: sivarajb
3 Replies

7. UNIX for Dummies Questions & Answers

Count number of files in directory excluding existing files

Hi, Please let me know how to find out number of files in a directory excluding existing files..The existing file format will be unknown..each time.. Thanks (3 Replies)
Discussion started by: ammu
3 Replies

8. Shell Programming and Scripting

Unzip files without overwriting

Hi, 1)I have two zip files a.zip and b.zip. a.zip contains the files a.txt,b.txt and c.txt b.zip contains the files a.txt,b.txt,d.txt,e.txt Though some of the filenames in a.zip and b.zip are same, the size is different,i.e., the files are completely different even though their name is same.... (1 Reply)
Discussion started by: donisback
1 Replies

9. Shell Programming and Scripting

How to copy one folder to another with existing files

For example, /tmp/folder1 includes /tmp/folder1/a /tmp/folder1/b /tmp/folder2 includes /tmp/c Is there a command without removing files in /tmp/folder2 first to copy the /tmp/folder1 to /tmp/folder2? and the result should be /tmp/folder2 will include only /tmp/folder2/a... (2 Replies)
Discussion started by: lalelle
2 Replies

10. Solaris

ls does not display existing files

Hi, I have a pecular problem that I am experiencing. I have a few directories that seems to be missing, however, I can vi the files within them and I can also execute them (script files). For missing, I mean when I issue the "ls" command I don't see anything. Any help will be greatly... (1 Reply)
Discussion started by: copperUser
1 Replies
Login or Register to Ask a Question