Avatar of missymadi
missymadi
 asked on

How to ssh to a local VM and copy a file?

Experts,

      I have started a script to automate a tedious setup of our environment. I was wondering how to ssh into a VM and backup a file then replace with an updated file?

Thanks, Missymadi
#/bin/bash

#reroute traffic
route add -host 00.00.00.00 netmask 0.0.0.0 gw 0.0.0.0

#make backup file
cp /home/rc/file1 /home/rc/file1ORIG

#copy new file 
cp /home/rc/

#need to ssh into a local VM
ssh root@00.00.00.00

#reroute traffic
route add -host 00.00.00.00 netmask 0.0.0.0 gw 0.0.0.0

#make backup file
cp /home/rc/file1 /home/rc/file1ORIG

#copy new file 
cp /home/rc/

Open in new window

LinuxShell Scripting

Avatar of undefined
Last Comment
missymadi

8/22/2022 - Mon
wesly_chen

The script is run in VM or from the server?
missymadi

ASKER
I wanted the script to run on the local Centos 5. I was trying to avoid two scripts
wesly_chen

And what commands in the script are running in VM?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
missymadi

ASKER
#reroute traffic
route add -host 00.00.00.00 netmask 0.0.0.0 gw 0.0.0.0

#make backup file
cp /home/rc/file1 /home/rc/file1ORIG

#copy new file
cp /home/rc/
ASKER CERTIFIED SOLUTION
wesly_chen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
missymadi

ASKER
wesly_chen
  For the VM, it depends on how the VM ended.  Meaning, did the user save the VM state or did they log all the way off. If the user logged all the way off, yes the VM will ask for a password.

I think I should stick to two separate scripts. I don't want  my script to fail and confuse the user.