Remove file conditionally between two server using sftp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove file conditionally between two server using sftp
# 1  
Old 04-05-2010
Remove file conditionally between two server using sftp

Hi,
I am having 2 servers, Need to delete files from server1 if those files exist in server2 other wise no action using sftp .And the process is non-interactive way. I have got confused how to check the condition in sftp because there is non of the shell condition or loop command is executing.
In locally i can do the same problem but how to get result in sftp .
Code:
#!/bin/sh
source=~/abc/xy/
dest=~/def/yz/
for file in `ls -1 $dest`
do
if [ -e $source/$file ];then
rm -f $source/$file
fi
done

how to do this condition checking in sftp.

Thank you
posix
# 2  
Old 04-06-2010
why don't you use rsh or ssh.
Here is a sample one you need to modify as per your requirement.

Code:
local=~/abc/xy/
remote=~/def/yz/
for file in `ls -1 $local`
do
rsh -n -l user 10.10.10.10 " ls $remote/$file"  

if [ $? eq 0 ];then
rm -f $source/$file
fi
done

# 3  
Old 04-06-2010
Delete files from server using SFTP

Actually in the remote directory i am having several types of files, i want to delete a particular type of files let the directory having .xml and .txt files. how could we delete the particular type of files (.xml) using the rm command in sftp.Script need to run in cron. I failed to retrieve all the .xml files.
Code:
$remove_remote.sh
#!/bin/sh
user=abcd
passwd=blahblah
ip=1.2.3.4
ext=.xml

lftp -u ${user},${passwd} sftp://${ip}<<EOF
cd ${path}
rm *${ext}                                                                                   
bye
EOF

Is there any other method to do so.

Thank you
posix

Last edited by posix; 04-07-2010 at 02:31 AM.. Reason: code tag
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need some help regarding file transfer between server (sftp/scp)

Hi All, Need some help regarding file transfer between server. Suppose we have system-A and system-B. To transfer file from system-A to system-B we usually share the public keys of system-A to system-B and do scp/sftp to transfer a file. Is it possible that public key of system-B can be... (3 Replies)
Discussion started by: abhi_123
3 Replies

2. Shell Programming and Scripting

SFTP files to a file server.

Hi, I am looking for a shell script to sftp to a file server and copy all the files from a directory after the script is run. The server name should be a user input parameter and of-course the username/password as well. Rest all should be handled by the script. I tried with below... (3 Replies)
Discussion started by: happysingh
3 Replies

3. Shell Programming and Scripting

How to conditionally display and remove first line only?

I have a maildir hierarchy of 90k eml files and; 1) I would like to walk the tree and display the first line from any file, whose first line begins with; From - That's "From space dash space" and only if it's the first seven characters, of the first line in the file. 2) I would also... (12 Replies)
Discussion started by: jasn
12 Replies

4. Shell Programming and Scripting

SFTP problem......File not getting from Remote server

Hi, We are using one unix script which is using sftp command and connect to remote server and get some file form remote server. some time after running this script we are not getting any file . Could you please tell us detailed validation that is there any problem with... (6 Replies)
Discussion started by: maheshkumar93@g
6 Replies

5. Shell Programming and Scripting

Generate file and Upload to SFTP server.

Xperts, My requirement is something like this, I have a sql script which i need to embed in a shell. The sql (oracle) script will generate a .csv file in some Unix directory. the approximate file size is around 10 mb which i need to upload to an sftp server. My concern here is how to make... (5 Replies)
Discussion started by: Showdown
5 Replies

6. Shell Programming and Scripting

SFTP - Get size of file on remote server

Hi, I have a requirement where I need to do SFTP connection to remote server, get the size of the file on remote server and depending on the size, i need to get the file onto local server. Is there any command in SFTP to get the size of the file. I found one in FTP but not in SFTP (2 Replies)
Discussion started by: forums123456
2 Replies

7. Shell Programming and Scripting

Remove specified file from sftp

Hi, I want to delete specified file from sftp by running the script in crontab also i want to keep log of the script , mean what files are it removing. so far.. user=abcde passwd=xxxxx ip=1.2.3.4 path=/dir1/dir2 ext=.txt lftp -u ${user},${passwd} sftp://${ip}<<EOF 2>>/root/remote_log.txt... (0 Replies)
Discussion started by: posix
0 Replies

8. Shell Programming and Scripting

Remove newline character conditionally

Hi All, I have 5000 records like this Request_id|Type|Status|Priority|Ticket Submitted Date and Time|Actual Resolved Date and Time|Current Ticket Owner Group|Case final Ticket Owner Group|Customer Severity|Reported Symptom/Request|Component|Hot Topic|Reason for Missed SLA|Current Ticket... (2 Replies)
Discussion started by: j_53933
2 Replies

9. UNIX for Dummies Questions & Answers

SFTP file from unix box to a NT server

Hi, I've searched but I haven't found a clear answer on this. Is it possible to sftp a file from a unix box to an NT server (windows)? If it is possible how do I go about doing it? Any help would be much appreciated! Thank You! (5 Replies)
Discussion started by: queenie680
5 Replies

10. Shell Programming and Scripting

sed csv remove conditionally

Hello, I have many csv file, but I would like to delete lines with some values in a column conditionally. My example look like this, ex1e, ex2g, ex39, pasg, ssg, mrlc, pc, kb, coop -112, -53, -177, 64, 62, 71, 1, 487, 20 -101, -61, -53, 0, 32767, 51, 0, ... (6 Replies)
Discussion started by: Jae
6 Replies
Login or Register to Ask a Question