how to scp file from serverA to serverB

Posted on 2011-02-18
Last Modified: 2012-05-11
how to scp a file from server A to Server B where serverB user is different then server A

on serverA
$ls -l
-rw-r--r--  1 userA users 2584 Feb  1 09:18 first.xml

my script should create a directory on serverB and copy my file as well

usually i do open a seperate ssh window
on serverB
ssh webadmin@serverb
mkdir /tmp/web

on serverA login as userA
$ls -l
-rw-r--r--  1 userA users 2584 Feb  1 09:18 first.xml
$scp first.xml webadmin@serverb:/tmp/web

Then i login into serverB and run
$cd /tmp/weblogic
$sudo -u webadmin cp first.xml /usr/local/weblogic

please provide single scp command which will do all these steps
Question by:wasman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 48

Expert Comment

ID: 34929246
Why do you copy it to a temp directory in the first place?

Why not just do
scp /usr/local/weblogic/first.xml webadmin@serverb:/usr/local/weblogic

Open in new window


Author Comment

ID: 34929457
bcz i don't have password for webadmin user on serverB, after i login to that box i can sudo that webadmin user
LVL 48

Accepted Solution

Tintin earned 500 total points
ID: 34929544
The only way you're going to make it a single step is to either have sudo privs on serverA, in which case you can do

sudo -u webadmin scp /usr/local/weblogic/first.xml webadmin@serverb:/usr/local/weblogic

or have your .ssh installed on serverB in the webadmin account.
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button


Author Comment

ID: 34955574
 sorry for late reply,
you are right,
Another question, how to run a set of unix commands, in a single ssh command
ssh webadmin@serverb:`mkdir /tmp/raju ; touch /tmp/raju/kaju.txt ; /usr/local/web/`
Please correct above command
LVL 48

Assisted Solution

Tintin earned 500 total points
ID: 34955817

ssh webadmin@serverb "mkdir /tmp/raju ; touch /tmp/raju/kaju.txt ; /usr/local/web/"

Open in new window


Author Closing Comment

ID: 34956236

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question