Solved

how to scp file from serverA to serverB

Posted on 2011-02-18
6
503 Views
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
exit

on serverA login as userA
$pwd
/usr/local/weblogic
$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
0
Comment
Question by:wasman
  • 3
  • 3
6 Comments
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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

0
 

Author Comment

by:wasman
Comment Utility
bcz i don't have password for webadmin user on serverB, after i login to that box i can sudo that webadmin user
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
Comment Utility
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.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

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

Assisted Solution

by:Tintin
Tintin earned 500 total points
Comment Utility

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

Open in new window

0
 

Author Closing Comment

by:wasman
Comment Utility
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now