Automatic scp Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatic scp Script
# 1  
Old 04-24-2018
Automatic scp Script

I need a script to automatically scp the latest files on DIR1,DIR2 and DIR3 from Source to destination server at same place(DIR1,DIR2 and DIR3) . Further details are:

Code:
Source Server (192.168.1.5)
DIR1
DIR2
DIR3

Destination Server (192.168.1.10)
DIR1
DIR2
DIR3


Last edited by jim mcnamara; 04-24-2018 at 10:09 AM.. Reason: code tags
# 2  
Old 04-24-2018
If you tell us your OS and shell it would help to give you a better answer. A lot.

Please show us what you have tried. Thanks.
# 3  
Old 04-25-2018
I am new in shell scripting thats y i need a help to create a script. please help me
# 4  
Old 04-26-2018
Quote:
Originally Posted by refra
I am new in shell scripting thats y i need a help to create a script. please help me
Once again: we are willing to help, but:

- which OS do you use? (and which verson of it?

- which shell do you use?

- do you have SSH-keys already exchanged between the servers so that the transfer can be passwordless?

We need to know that before we can provide you an answer. If you call the doctor and tell him "it hurts" he would ask "where" and "how long" too before starting to suggest a cure, no?

bakunin
# 5  
Old 04-26-2018
The output of uname -a and ps would be a good place to start on both the client (where you want to drive this from) and the server (where you are connecting too.

Can you log on from the client to the server without putting in the password? This would show that the SSH keys are in place and correct.


Kind regards,
Robin
# 6  
Old 04-27-2018
- which OS do you use? (and which verson of it?
SUSE Linux 11 Ent

- which shell do you use?
Bash

- do you have SSH-keys already exchanged between the servers so that the transfer can be passwordless?
Yes
# 7  
Old 04-27-2018
Thank you for that information. So, is the question "How do you know which is the latest file?" ?

Can you do something like this?:-
Code:
#Turn on shell tracing so we can see what's being called
set -x

#Work out the file I need to get
source_file=$(ssh $server "ls -1rt DIR1 | tail -1" 2>/dev/null)
echo "The source file is \"$source_file\""

# Collect the file, writing it to the directory I need
scp $server:$source_file $target_directory


It's not tested, but have a go and let's see if it gets us further. Obviously, set the server and target_directory to something useful first.


It is likely not to work first time, so paste the output in CODE tags into the thread so we can see where I have gone wrong.



Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automatic script trigger

Hi, I'm looking for a way to solve the following scenario: A shell should automatically trigger / run when a text file is placed or present at a specific location. My idea - to create a cron / anacron for every minute and inside that i will call a temp script. Temp script will move to my... (9 Replies)
Discussion started by: Gautham
9 Replies

2. UNIX for Dummies Questions & Answers

Automatic counter script

Hello, I am having trouble calculating some numbers and I was hoping someone could help me solve this. I have one file with 1 column and what I'm trying to do is add up the lines until a certain value is reach, then jump to where it last finished counting and continue. so for ex: if I... (27 Replies)
Discussion started by: verse123
27 Replies

3. Cybersecurity

automatic SCP transfers issues

Hi, I'm trying to set up scp but it isn't as nice as WinSCP. My requirement is to transfer a file from one machine to another with scp. This would run in a .ksh so it would need to avoid prompts (password/are you sure). First I tried this with v2: SSH with Keys HOWTO: SSH with Keys in a console... (1 Reply)
Discussion started by: Dird
1 Replies

4. Shell Programming and Scripting

automatic execution of script after every 10 mins

Hi All, I have a requirement that a script need to be executed automatically every 10 mins. how is this possible. lots of logs are created as a part of process and the logs need to be moved into a directory. how is this possible ? (1 Reply)
Discussion started by: suresh_kb211
1 Replies

5. SCO

Automatic FTP script

We are using SCO OS 5.05 server and we are doing a manual ftp to another SCO OS 5.05 server to backup our database. We are using the Bourne shell. We would like to automate the ftp backup of our database instead of doing it manually. It would be nice to run a script. Also would there be anyway... (4 Replies)
Discussion started by: texastig
4 Replies

6. Solaris

Script for automatic deletion of old folder

Hi, I have a folder with limited space. So i have to delete folder which are more than 5 days old automatically. So my script should be like delete the folder more than 5 days old. Can someone help me to generate a script for this. Thank you... Cheer Summer (5 Replies)
Discussion started by: summerpeh
5 Replies

7. Shell Programming and Scripting

automatic scp download (without the use of ssh keys)

Hi guys, I need to automate scp downloads from a server to which I do not have the ability to upload my public key for automatic logins. I know there is something called expect, but I wasn't sure if that was the best way to go. Basically I am executing a scp download command and I need the... (2 Replies)
Discussion started by: caprica13
2 Replies

8. UNIX for Advanced & Expert Users

Automatic script

Hi, is it possible to automatically run a script (bash) when an event occurs? I mean, let's say that I (or one of my users) plug in a flash memory (USB) ... is it possible to run a script every time I do this action (let's say to log user, date and other infos on a file)? Thanks! Bye... (5 Replies)
Discussion started by: TShirt
5 Replies

9. Shell Programming and Scripting

automatic transfering of files using scp

I'm in the process of writing a shell script with copies files from one linux box to another using scp. I wish to run this through a cronjob so it cannot be interactive. This is what I have so far. #!/bin/sh PASSWD='passswd' dateset=$( date | awk '{print $2 $3 $6}') for dates in $dateset;... (1 Reply)
Discussion started by: tcruicksh
1 Replies

10. Shell Programming and Scripting

Automatic login script

Hi, I'm a beginner in unix.As a part of my script i need to remote logon using ssh. my script run as being asked for password and logons only after the user enters the password correctly. But my script stops executing after that as I login to a different server(different shell if i'm right).... (3 Replies)
Discussion started by: dayanand
3 Replies
Login or Register to Ask a Question