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

2006-07-03 Thread [EMAIL PROTECTED]
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 [EMAIL PROTECTED] % 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 [EMAIL PROTECTED] % 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 [EMAIL PROTECTED] (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,

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-02 Thread Ove Pettersen
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 [EMAIL PROTECTED] (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,
-- 
http://mail.python.org/mailman/listinfo/python-list


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

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

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

Petr Jakes

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-02 Thread Michael Abbott
Ove Pettersen [EMAIL PROTECTED] wrote:
 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
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread gavino
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?

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread Ravi Teja

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.

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread LittlePython
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 [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 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.



-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread gavino
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.

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread Ravi Teja
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.

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread LittlePython
thx,


Ravi Teja [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 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.



-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread Ravi Teja

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.

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread [EMAIL PROTECTED]
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.

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread Paul McGuire
gavino [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 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



-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-07-01 Thread Thorsten Kampe
* gavino (2006-07-01 11:34 +)
 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
-- 
http://mail.python.org/mailman/listinfo/python-list