How would I write this script in the Linux OS?

metsrangerfan294

New Member
Joined
Mar 24, 2021
Messages
1
Reaction score
0
Credits
13
I would like to write a python script. It needs to do the following:
cp /home/caspida/.ssh/authorized_keys caspida@<remoteserver>/home/caspida/.ssh/authorized_keys
the <remoteserver> piece needs to be read in from a dynamic file of up to 40 servers that I can edit when I need too
The extension should be .py
 


why not a shell script? (and tcsh b/c that's the kind of guy I am)
and leave off all the username stuff s.t. it works for whomever runs it.
I'll leave it to you to add the "USAGE" statement that checks to make sure $1 is defined on the command line or to loop over multiple machine names.

Of course if all machines share a common home directory that would solve the problem too :)

copykeys machinename

copykeys
#!/bin/tcsh
scp ~/.ssh/authorized_keys $1~/.ssh/authorized_keys
 
Because configuration management tools are built for tasks such as the one you are wanting to write a shell or python script for. Why reinvent the wheel? How Ansible basically works, you create a set of tasks and run those over an inventory and you are able to control what happens by creating conditions for those tasks when they are executed. For what you are trying to do you what basically only have to setup a task that copies the file from a local directory where you run Ansible from to all the systems in your inventory, you only need a ssh connection to those systems in your inventory.
 
Last edited:
True... but if you only need a little tread and not a whole tire.... I'm just saying there may be other issues at play
 
True... but if you only need a little tread and not a whole tire.... I'm just saying there may be other issues at play
Because Ansible is quite simple to setup because it only requires an ssh connection and you can make it as simple or complicated as you want even just writing one task for this specific goal that OP is trying to achieve.
 

Members online


Top