I have a script that uses pexpect to ssh to a list of servers and will run a user specified command on each server. I have tried to use pexpect logging to output the results of each command to a file so the user can see the output (of commands such as uptime and ntpdate). The remote servers are both Solaris and Red Hat. For some reason, not all output is captured in the file.
Here is my code:
Some code unnecessary and snipped...
User Profile
Collapse
-
Part of the problem is that not all of the 4 items in EnvList need to exist.
For example, if I want to pick just the Solaris servers out of the ServerList then EnvList will only contain
['Solaris']
EnvList is created through a series of menus from which the user will pick only then EnvList items that they need. -
Check if a tuple contains a string
I have a tuple of a tuple (ServerList) that contains the following:
<host1>,DEV,Inf ormatica,Red_Ha t,64
<host2>,PROD,In formatica,Red_H at,64
<host3>,PROD,In formatica,Red_H at,64
<host4>,QA,Info rmatica,Red_Hat ,64
<host5>,PROD,Ti bco,Solaris,
<host6>,TEST,Ti bco,Solaris,
I have a list (EnvList) that could contain the following:
['PROD','Informa tica','Red_Hat' ,'64']... -
That does look better than my code but still errors if the user does not enter a number (or, more importantly for this) just hits enter.Leave a comment:
-
Validate user input
I am requesting user input from a menu a script. The input I am requesting needs to be an integer. Is it possible to validate that the user actually entered an integer and not a string or just hit enter? Everything I have tried will give me
"File "<string>", line 0, in ?
NameError: name 'd' is not defined
The code I have looks like this:
...Code:def init_menu(): print ''' 0) Exit
-
In vi, at least, this will replace a number that is the first character on a line (lines 7-11 only) with the string "Toughie". The 'c' at the end will ask the user for confirmation.Leave a comment:
-
To do what you want, as written, is impossible. To change a user's primary group requires them to log out and log back in again. You will need to, as suggested above, use setGID to allow users to act on the directory as the primary group.Leave a comment:
-
You can use the cut (-b) command and specify what position in the string that you want to look at...From there you can use an if statement:
Just for a start...Code:for i in `cat <file>` do section=`echo ${i} | cut -b 87-89` if [[ ${section} == "003" -o ${section} == "004" then echo ${section} fi doneLeave a comment:
-
Sorry, forgot to declare data before...
data = []
(Is that declaring it as a dictionary? Is there a table that shows what each are ([], {}...)
JohnLeave a comment:
-
Would something like:
work?Code:import csv f = open(".servers.txt", "r") reader = csv.reader(f) for row in reader: data.append(row[0]: [row[1], row[2], row[3], row[4]) f.close
ThanksLeave a comment:
-
Using data from csv file several times
I am new to Python. I am trying to port a BASH script I wrote to Python so I can learn the language.
I have a csv file with 5 columns. The first column is a host name. Second through 5th have different attributes of the host (environment, use, OS, architecture). I want to allow the user to pick one type from each column and output the hostnames that match the users request (i.e. list all hostnames that are Oracle servers in Production running...
No activity results to display
Show More
Leave a comment: