Help with script periodically pushing files from one host to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script periodically pushing files from one host to another
# 1  
Old 10-15-2012
Help with script periodically pushing files from one host to another

Dear all,

I would like to write a script to push periodically some downloaded files from one host to another box.

Basically, I have host A downloading files.
When those files are downloaded they are moved automatically to a directory called: /home/user_A/downloaded, still on host A.

Then I need to move all the files in the downloaded directory from host A to host B, furthermore I want to clear up the downloaded directory on host A, as otherwise there won't be enough space there for future downloads.

So I want to write a shell script that:
1) periodically push all the files from the downloaded directory on host A to host B
2) Afterwards deletes all the files in the downloaded directory of host A

What is the best way to do that?

I would like to call this "push.sh" script, every hour in a cron job on host A:
Code:
push.sh
#!/bin/bash
cd /home/user_A/downloaded
scp * user_B@192.168.1.10:/home/user/store -user_B_passwd
rm -f *

My problem is: How to be sure that all the files are going to be completely transferred to host B before they are deleted on host A???
What should I do to be sure that the scp command is finished before executing the rm -f * command??

Many thanks for your help and keep up the good work!
freddie50
# 2  
Old 10-15-2012
Check the return code:
Code:
cd /home/user_A/downloaded
scp * user_B@192.168.1.10:/home/user/store -user_B_passwd
if [[ $? = 0 ]] then
  echo "File(s) have been moved..."
else
  echo "Error moving files..."
  exit 1
fi
rm -f *


In addition you could do a compare on the from/to directories before doing the 'rm':
Code:
# Before 'scp'
ls -1 /home/user_A/downloaded/* > from_dir.txt
# After 'scp'
ssh user_B@192.168.1.10 'ls -1 /home/user/store/*' > to_dir.txt

then do a 'diff' on the two files

This User Gave Thanks to spacebar For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

MQ depth Periodically

Hi I am trying to a write a script which gives message queue depth for every 5 mins in a file. Commands that I use are runmqsc QM_Name display ql(*) curdepth Since I can use only MQSC commands I need help on how to fetch the output on to a file after executing display command. (3 Replies)
Discussion started by: jhilmil
3 Replies

2. Shell Programming and Scripting

expect script pushing ssh keys w/ tar extract

ok, I'm new to the forum and I did a few searches and didn't find much on this so here goes. I have a ksh I use to call an expect script that opens a ssh session and then extracts a tar file. The tar file has my prefered .profile and my ssh keys. I want to run this script 1 time on new servers and... (2 Replies)
Discussion started by: gtsonoma
2 Replies

3. UNIX for Dummies Questions & Answers

Transfer large number of files host to host

Hello.... I have two servers, one has an empty / and the other has a subdirectory with a large number (4 gig) with many, many files. I need a way to transfer the files en masse from the server with the large number of files to the one that is essentially blank. I don't have space on the used... (16 Replies)
Discussion started by: blaine.miller
16 Replies

4. Shell Programming and Scripting

RSYNC syntax for pushing file with latest system date

OK, I am a little new to AIX 5.3 and also to scripting. I have a shell script that I wrote and am having difficulty pushing specific files by the system date. Here is my script: #!/usr/bin/sh RSYNC=/usr/local/bin/rsync SSH=/usr/local/bin/ssh KEY=<path> somekey.key RUSER=mike... (4 Replies)
Discussion started by: tfort73
4 Replies

5. Shell Programming and Scripting

ftp script to get files periodically

Hi Folks Interesting question hope u get the ans: I have to ftp a file ABC(Timestamp) to server XYZ My script should be doing the every 2 hours. after the transfer I need to confirm whether the file ABC(timestamp) got transfer properly or not. My concern is after the "put ABC"... (7 Replies)
Discussion started by: Haque123
7 Replies

6. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

7. Shell Programming and Scripting

script to send command periodically to remote server

Hi, I'm wondering if there's a way to send a command periodically to remote server through a script. Right now I have this: keepLooping=1 ssh user@domain while (( keepLooping == 1 )) do echo a sleep 3 done but what this does is ssh to the server, and only when the connection is... (2 Replies)
Discussion started by: sayeo
2 Replies

8. Programming

How to periodically execute a function in C ??

Hi, I am looking for a C library feature, to which I can say execute a function every 10 seconds. for Eg #include <timer_lib.h> fun1(){ printf("I am still cool "); } int main(){ run(10,&fun1); // Should register & execute the function fun1 every 10 seconds return 0x0; }... (24 Replies)
Discussion started by: RipClaw
24 Replies

9. Solaris

How to delete the files from local host to remote host

Hi all, i am copying .gz files from production server to development server using "scp" command.my requirement is after copying .gz files i want to delete old .gz files(two days back) in development server from production server. like this way i need to delelte .log ,.z and .dmp files... (3 Replies)
Discussion started by: krishna176
3 Replies

10. Shell Programming and Scripting

script working periodically

We have a strange problem that started happening a few months ago. We have a unix script being called from within a microfocus cobol program using the call "SYSTEM" cobol command. The problem is sometimes the script will run, sometimes it wont - without us changing anything! The other strange... (1 Reply)
Discussion started by: lf398
1 Replies
Login or Register to Ask a Question