Register
It is currently Wed Nov 26, 2014 3:16 pm

script for entering commands on remote computers


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Thu Sep 16, 2010 4:29 am   

Joined: Thu Sep 16, 2010 3:57 am
Posts: 11
I have 20 remote identical computers. I enter on them using ssh_authoriside_key. On every computers very often I need to enter the same commands.
I need a script that can chose the file with logins, pathes of ssh_keys and then lets me to enter commands which will send on every of the computers on the list.
Could You help me with this or suggest me to the right way.
Thank you


Top
 Profile  
 PostPosted: Thu Sep 16, 2010 10:28 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
I personally use onall, which is GPL from Ticketmaster;
http://code.ticketmaster.com/

Generally, once your ssh-agent has your keys loaded, it works like so...
Code:
echo host1 host2 host3 | onall -p 'my remote command'


We also wrote NHS (NiftyHostSelector) for scanning DNS for classes of server based on their hostnames.


Top
 Profile  
 PostPosted: Fri Sep 17, 2010 5:31 am   

Joined: Thu Sep 16, 2010 3:57 am
Posts: 11
Thank you very much! It help's :)


Top
 Profile  
 PostPosted: Fri Sep 17, 2010 9:07 am   

Joined: Thu Sep 16, 2010 3:57 am
Posts: 11
Now I'm trying to make a script where I can put many of my commands

I tried something like this but it stops after ssh-add

#!/usr/local/bin/bash

#ssh_script 0.1

ssh-agent $SHELL
ssh-add

echo -n "Enter USERNAME: "
read USER
echo -n "Enter command to execute on remote servers: "
read COMMAND
onall -u${USER} -y -f /home/tech/list '${COMMAND}'


I would like to have opportunity to write commands on few lines
something like this
ipfw add 104 allow udp from any to any 53 via vlan\*
ipfw add 105 allow udp from any 53 to any via vlan\*
ipfw add 106 allow icmp from any to me via vlan\*
ipfw add 107 allow icmp from me to any via vlan\*

Maybe the script must work in foreground and always receive my commands :) or it's impossible ?


Top
 Profile  
 PostPosted: Mon Sep 20, 2010 4:41 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Instead of putting the commands on the command line you can put them in a file as a script and tell onall to use the script using the -e switch, which will copy the script to tmp on each server and then run it.
You can also write commands on multiple lines, so long as you quote correctly like so;
Code:
onall 'command
command2
command'

or
Code:
onall 'command ; command2 ; command'


onall requires ssh agent to have keys, I have not tried using it in an automated job so I don't know anything about running ssh agent for that situation.


Top
 Profile  
 PostPosted: Wed Sep 22, 2010 2:24 am   

Joined: Thu Sep 16, 2010 3:57 am
Posts: 11
Thank you for the help


Top
 Profile  
 PostPosted: Mon Sep 27, 2010 9:27 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
There are a few commandline apps that do this....... also, if you have to use windows like I do, you can use SecureCRT and it has that built in, send the command to all open tabs. I've seldom used it, but it does work.


Top
 Profile WWW  
 PostPosted: Wed Sep 29, 2010 3:36 pm   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
onall is very powerful in an environment of hundreds/thousands of *nix servers. It has a good way of logging, runs parallel connections and timeouts. At some point I'll add an option to use a key file, if someone hasn't already :)
It's probably totally unsuitable for windows heh


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP