Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for script 1

Status
Not open for further replies.

seacros

Technical User
Jan 23, 2008
31
US
I am looking for a quick script to copy single file to 3 servers and then execute a command on the remote servers while displaying output on the server that I am copying the file from.

ex-
1. Create file on local machine (server A)
2. copy the new file to other servers (server b, server c, server d)
3. execute command on the remote servers (ex list users)
4. return output to txt or log file on the server that initiates the process (output to server A)

Thanks in advance.

 
Something like this?

Code:
# For each Server
for HOST in serverA serverB serverC
do
    # Copy the script
    scp script.sh user@${HOST}:script.sh

    # Run the script
    ssh user@${HOST} "./script.sh" >> script.log 2>&1
done

You would have to pre-share the SSH keys, but that's easy to do.

 
Thanks I will give it a shot.

SeaCros
 
I gave it a shot and it looked good. I do have an issue where one of the servers has a different directory that the other two. Is there a way to add another variable and path for the other server?

ServerA ServerB /export/home/User
ServerC /home/user

SeaCros
 
If you did it exactly as SamBones described it shouldn't matter what the user's home directory is; ./script will look in that directory by default.

Can you describe in more detail why the path is an issue?

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
I was able to figure it out. I had a typo. Seems to work as expected.

Thanks

Sean
 
One thing to just watch for is the dross (disconnected) ssh Fallback sessions (processes) left on the calling host machine after you have sent a ssh or scp command in a loop.

I see this often on Solaris machines (not sure if your Linux will behave the same) but it's easy to clean up just ps -ef then grep the ssh/scp Fallback process ID's and kill them off.

Laurie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top