Copy files to remote hosts and this lesson we are actually going to write a script.
This is also a for loop script very useful.
I use it many times and I know a lot of my friends who are in I.T. or in Linux have write scripts that
actually copies file from one location to multiple servers.
You could copy files from one system and two second system to third system using commands like FCP or
ACP.
But if you have multiple systems you don't want to do it one by one by one.
So this is a very short list and I want to show you how you could copy files and how you could use Foluke
commands for that.
And if you remember exactly how for a loop is done I'm sure by now you are expert in for loop.
And you should be able to do it yourself.
If not just follow me and will go into my machine and clear the screen.
I will name the script as copy files to remote.
And you know what we have to do
bin bash date.
Eight eight.
2020.
Scription
this script will copy files to remold.
Oh hey guys I miss one thing.
What is that art.
Yes.
Very important because if you are writing a script and you have multiple system engineers administrator
in your department they all start writing the script.
Then this is the easiest way to find out who wrote this.
And they will simply get in touch with you and ask you hey the script is not doing what we wanted to
do.
Can you modify it.
OK.
So now for
a pick I variable again and now you'll put the hostname or the IP address of the machine that you want
to trash where it just says for giggles or put the host name that's a red hat one red hat to Red Hat
three Red Hat four or as many servers as you want to transfer or you could do that.
So you know that now you're putting four Red Hat servers into a container and the container name is
OK.
It is in the container.
What do you want to do.
You wanted to do Sep of a file.
Right you want to transfer the file so the file name is like some file.
I don't know which good because this script that I'm writing is just a lab a test script.
I am not going to test or run the script because I do not have multiple Linux servers in my lab environment.
If you do have it then you could go in and actually change the host name right here which is right ahead
had 1 to 3 to the actual hostname that you have.
And to the actual some file to the actual file.
OK.
So you will SEPs some file where to I ise what is a container and the container has what container has
all your host names and colon slash that say you want to transfer to tip and this is right here is just
a standard way writing starting from column 2 if you change for transfer file and I'm sure you know
that and just be done.
So this is actually as you know let me repeat it again.
This is going to copy some file to read had 1 2 3 and 4.
And if you have multiple files you could also what you could do you could put all those files in a file
create a file let's say ABC and put all the list.
Let's say if you have hundred servers then you don't want to write those 100 so we're right here.
Then what do you have to do.
You have to specify a variable that would do a variable tick cat.
Def files the file is home I have Zoll ABC you catting the file.
Now you are telling it for file in
dollar a then you do same thing again.
So now you don't have to specify all your host names into the script.
You could just specify your hostname into a file and then you tell the script to go and read the file
and execute that command against it.
That's pretty much it about this lesson.
If you actually have multiple host that you could try on go ahead and try and I'm sure it'll work.