Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 19th, 2013, 09:46 AM
hrp2010 hrp2010 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 hrp2010 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m 42 sec
Reputation Power: 0
Python script automation

Need help sith pyton script for auto installation of RPM on number of redhat servers.

so far i was successfully able to copy rpm/directory to single redhat server. i wants to know how we can transfer it to multiple server and upon transfer i can i install rpm and edit file ?

#!/usr/bin/python
import os
os.system("scp -r xyz root@hostname:/root")

above will copy xyz directory to single host.

hints or conceptual idea would be greatly appericated.

thank you

Reply With Quote
  #2  
Old January 19th, 2013, 11:30 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 33 m 33 sec
Reputation Power: 403
I'd use bash, not python.
I'm sure you can
read
hostnames from a file as well.

man bash

Code:
for h in host1 host2 
do
  scp -r xyz root@$h:/root
done
If you must have python, roughly
Code:
import os
hostnames = populate(a_file)  # list from a file
for host in hostnames:
    os.system("scp -r xyz root@{}:/root".format(host))
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 19th, 2013, 03:15 PM
hrp2010 hrp2010 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 hrp2010 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m 42 sec
Reputation Power: 0
Thank you very much for your quick response. I tested but
i am getting below error message while running as per you recommendation.

did we need to import module related to "populate" ? If so what is that ?

Traceback (most recent call lst):
File "./xyz.py, line 3,in <module>
hostnames=populate(a_file)
NameError: name 'populate' is not defined.


Also my ultimate goal is after i copy directories on various servers, that directory contains couple rpm's which i need to install on each server, open a specific file and search for word an xyz="xyz" and replace "xyz" with "hostname" and another line in the same file, starting with ddd="sss" and replace "sss" with "hostname" , restart deamons by /etc/init.d/xyz restart

your help is very much appericated.
thank you

Reply With Quote
  #4  
Old January 19th, 2013, 04:01 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 33 m 33 sec
Reputation Power: 403
You're supposed to write populate. I presume your list of host names is in a file. You'd read the file into a list.

Suppose your hosts are a b and c.

def populate():
return ['a','b','c']


would work.

Reply With Quote
  #5  
Old January 20th, 2013, 04:53 PM
hrp2010 hrp2010 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 hrp2010 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m 42 sec
Reputation Power: 0
does not work. do you mind putting newly advised code with explanation ? thank you. a_file is where i am putting all hostnames. i found that if i use as below to copy directory to a multiple systems but i would like to avoide that as i like concept of reading all hosts from a single file and script read that file in order to login and than copy.
os.system("scp -r xyz root@hostname:/root")
s.system("scp -r xyz root@hostname1:/root")

Also after directory being copied, i can i go to that xyz directory and run "rpm -ivh xyz.rpm" ( install a package ) or multiple commands like that ?

thank you

Reply With Quote
  #6  
Old January 20th, 2013, 09:01 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 33 m 33 sec
Reputation Power: 403
Code:
def populate():
    with open('a_file','r') as inf:
        hostnames = inf.readlines()
    return [host.strip() for host in hostnames]
For the other question, you can run ssh . You can run ssh from python. I still don't know why this extra python layer is useful.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python script automation

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap