469,964 Members | 1,735 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

I have 100 servers which need a new backup server added to a text file, and then the backup agent restarted.

This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers.
What script would allow this?

Jul 1 '06 #1
13 2185

gavino wrote:
This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers.
What script would allow this?


Try pxssh from pexpect. Look at the sample in the page.
http://pexpect.sourceforge.net/pxssh.html
It will allow you to automate ssh interactions.

Jul 1 '06 #2
Does this require a ssh client or server?

I use authpf to open up my PF firewall for internet use. Generally I just
open up putty and make a connection to the FW ( which open the ports) and
minize it till I am done. When I close putty authpf losses the ssh session
heartbeat and will then instruct the FW to close the ports. I would love to
write a simple client to do this form me instead of using putty. Do you
think these mods would work for me on a windows platform?

Thx

"Ravi Teja" <we*********@gmail.com> wrote in message
news:11**********************@v61g2000cwv.googlegr oups.com...

gavino wrote:
This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers.
What script would allow this?


Try pxssh from pexpect. Look at the sample in the page.
http://pexpect.sourceforge.net/pxssh.html
It will allow you to automate ssh interactions.

Jul 1 '06 #3
list of servers L.txt
#cat L.txt
config file is /var/bkupexec/agent.cfg need to add "tell epobackup" to
bottom of file
# cat "tell epobackup" >> /var/bkupexec/agent.cfg
agent is /etc/init.d/agent.ini stop (and then start)
# /etc/init.d/agent.init stop
# /etc/init.d/agent.init start
os=redhat ent 4ES
I intend to use root password which is same for all 100 servers.
#now I'm stuck

Ravi Teja wrote:
gavino wrote:
This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers.
What script would allow this?


Try pxssh from pexpect. Look at the sample in the page.
http://pexpect.sourceforge.net/pxssh.html
It will allow you to automate ssh interactions.


Jul 1 '06 #4
LittlePython wrote:
Does this require a ssh client or server?

I use authpf to open up my PF firewall for internet use. Generally I just
open up putty and make a connection to the FW ( which open the ports) and
minize it till I am done. When I close putty authpf losses the ssh session
heartbeat and will then instruct the FW to close the ports. I would love to
write a simple client to do this form me instead of using putty. Do you
think these mods would work for me on a windows platform?

Thx
Pexpect needs a POSIX system. However, you can use Cygwin.
From the website, "Pexpect does not currently work on the standard

Windows Python (see the pty requirement); however, it seems to work
fine using Cygwin."

Jul 1 '06 #5
thx,
"Ravi Teja" <we*********@gmail.com> wrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
LittlePython wrote:
Does this require a ssh client or server?

I use authpf to open up my PF firewall for internet use. Generally I just open up putty and make a connection to the FW ( which open the ports) and minize it till I am done. When I close putty authpf losses the ssh session heartbeat and will then instruct the FW to close the ports. I would love to write a simple client to do this form me instead of using putty. Do you
think these mods would work for me on a windows platform?

Thx


Pexpect needs a POSIX system. However, you can use Cygwin.
From the website, "Pexpect does not currently work on the standard

Windows Python (see the pty requirement); however, it seems to work
fine using Cygwin."

Jul 1 '06 #6

gavino wrote:
list of servers L.txt
#cat L.txt
config file is /var/bkupexec/agent.cfg need to add "tell epobackup" to
bottom of file
# cat "tell epobackup" >> /var/bkupexec/agent.cfg
agent is /etc/init.d/agent.ini stop (and then start)
# /etc/init.d/agent.init stop
# /etc/init.d/agent.init start
os=redhat ent 4ES
I intend to use root password which is same for all 100 servers.
#now I'm stuck


Read L.txt from (not your shell as you seem to be doing) Python and
connect to each one from pxssh, and send the commands you listed. I am
afraid, you will have to readup and experiment on a smaller scale. The
sample I pointed you to is a rather simple one and you don't seem to
have even tried it.

Jul 1 '06 #7
I would sugest looking at http://pexpect.sourceforge.net/ The Expect
metalanguage was specifically designed for the kind of things you are
trying to do. I used it recently on a project to configure 25
instances of an application, remotly, half over ssh half over telnet.

Jul 1 '06 #8
"gavino" <bo******@yahoo.comwrote in message
news:11*********************@d56g2000cwd.googlegro ups.com...
This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers.
What script would allow this?
Could this project help you? http://sourceforge.net/projects/distribulator/

It sounds similar to what you describe.

-- Paul

Jul 1 '06 #9
* gavino (2006-07-01 11:34 +0000)
This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers.
What script would allow this?
Tentakel
Jul 2 '06 #10
gavino wrote:
This seems easy but I have been asking tcl and python IRC chat all day
and no one gave an answer.
I have 100 servers which need a new backup server added to a text file,
and then the backup agent restarted.
If I have a list of the servers, all with same root password, and the
connection is ssh.
How do I connect to the server, cat the line to the config file, stop
adn start the agent, and then do same to next server in list and
iterate through the 100 servers.
What script would allow this?
I wouldn't use python at all (like swearing on this list???) .... simple
shell-command is more than sufficient.

for server in "server1 server2 server3 .... server100"
do
ssh root@$server "(echo "new line" >config.file; stop-command ;
sleep 5 ; start-command)"
done

I would however have extended the procedure with a few more checks...
Like:
* only add new line to config-file if it isn't present
* only do restart if config-file was modified

Regards,
Jul 2 '06 #11
gThis seems easy but I have been asking tcl and python IRC chat all day
gand no one gave an answer.
gI have 100 servers which need a new backup server added to a text file,
g and then the backup agent restarted.
gIf I have a list of the servers, all with same root password, and the
gconnection is ssh.
gHow do I connect to the server, cat the line to the config file, stop
gadn start the agent, and then do same to next server in list and
giterate through the 100 servers.
gWhat script would allow this?

Maybe webmin could help. http://www.webmin.com/
You can manage cluster of servers at once.

Petr Jakes

Jul 2 '06 #12
Ove Pettersen <ov***********@smartcall.nowrote:
for server in "server1 server2 server3 .... server100"; do
Two comments:

1. Leave out the quotes(!)

2. Either iterate as
for server in $(seq -fserver%g 100); do
or, probably better
for server in $(cat server-list); do
Jul 2 '06 #13
Hehe, yeah, it does feel like swearing =)

That solution works, as long as the network behaves PERFECTLY and
you've allready configured the server to use your SSH key instead of a
password. Expect, by its nature, waits until the right time to say
things

Sample pexpect code:
------------- Code -------------
# assumes hosts is a list of hostnames
for host in hosts:
child = pexpect.spawn("ssh root@%s" % host)
child.expect ('Password:')
child.sendline ("the correct root password")
child.expect ('#') # root prompt
child.sendline("echo 'the new line' >/etc/config.file")
child.expect('#')
child.sendline("/etc/init.d/myservice restart")
child.expect("#")
child.sendline("logout")
-----------------------------

Or if you prefer a stronger split between data and code you can use
this code. If you need even more functionality than that (such as
pausing for a few seconds after a command), you can start using
callable objects instead of tuples of text.

------------- Code ---------------
# commands is a list of (text-to-wait-for, response-to-send) pairs
commands = [ \
("Password:", "the correct root password"), \
("#", "echo 'the new line' >/etc/config.file"), \
("#", "/etc/init.d/myservice restart"), \
("#", "logout") ]

for host in hosts:
child = pexpect.spawn("ssh root@%s" % host)
for cmd in commands:
child.expect(cmd[0])
child.sendline(cmd[1])
-------------------------------------------------

You can also tell pexpect to have a timeout on any expect() call.

Shell has its uses. My personal experiance is shell's use is when you
dont expect the client to have a more powerful language installed, or
when a scripts duties are very limited. If ANYTHING involves a space,
dont bother with shells, handling spaces will take more debugging than
the actual code. For example, your quickly written code wouldn't work
because you have " inside ", when you needed single quotes. And if any
of the commands issued have difficult parameters, properly escaping
shell strings is an utter nightmare. A shell solution may work here,
but if the task gets any more complicated, then a new language is
needed.

I'm a toolkit programmer - I keep as many language as I can in my
toolkit. Pexpect was 100% designed for this specific task, so why not
use it. If I was parsing a text file, 9 times out of 10 I'll pull up
PERL, its ment for it.
Ove Pettersen wrote:
>
I wouldn't use python at all (like swearing on this list???) .... simple
shell-command is more than sufficient.

for server in "server1 server2 server3 .... server100"
do
ssh root@$server "(echo "new line" >config.file; stop-command ;
sleep 5 ; start-command)"
done

I would however have extended the procedure with a few more checks...
Like:
* only add new line to config-file if it isn't present
* only do restart if config-file was modified

Regards,
Jul 3 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Charles Morrall | last post: by
3 posts views Thread by ChrisWinterscheid | last post: by
3 posts views Thread by alwinkotiya | last post: by
2 posts views Thread by garther | last post: by
4 posts views Thread by phirestorm | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.