[Tutor] Opsware Global Shell Scripting

Kayvan Sarikhani ksarikhani at gmail.com
Wed Jan 7 22:04:28 CET 2009


Hi there...I'm new to Python scripting, with maybe 3 days under my belt thus
far. Besides the occasional shell script, the last time I ever touched a
programming language was probably at least 12 years ago, if that gives you
any indication of my experience. :)

I don't know if this is the proper place to ask, but I've run into the
problem below.

Right now I'm beginning to work within the Opsware Global Shell, which if
you're unfamiliar with it, basically is exactly what it sounds like...the
goal is to launch a script which changes directories to a list of servers,
prints the server name, remotes into managed virtual servers, checks the
date, and outputs this into a file. I do have a bash script as follows,
which does the job:

#!/bin/bash
#
# This script checks the dates on all managed systems.
OUTFILE="/home/ksarikhani/public/bin/timecheck.txt"
rm -f $OUTFILE
cd "/opsw/Server/@/"
for SERVER_NAME in *
do
       echo ---- $SERVER_NAME
          echo ---- $SERVER_NAME >> $OUTFILE
            rosh -n $SERVER_NAME -l $LOGNAME \
                    "date" >> $OUTFILE
done
# Last line in date.sh.

Even though the above does what I need it to do, I'd REALLY like to
determine the equivalent in Python...I've tried several different methods,
but about as far as I get is printing the server name. This is what I've
cobbled together so far.

#!/usr/bin/python
import os, sys
sys.stdout = open('timecheck.txt','w')
for servername in os.listdir('/opsw/Server/@'):
    print '---', servername
    os.system('rosh -n $SERVER_NAME -l $LOGNAME')
    os.system('date')
sys.stdout.close()

The problem is this...for logging into systems via the global shell, one has
to change directories to the one with the list of all managed servers (or
specify the path for each one), and then launch a "rosh -n <hostname> -l
<username>" to be able to get into it.

However, when I launch the script, what happens is the following message:
*rosh: Username must be specified with -l or via path*

And this is a continual loop that I can't break.

This is of course not a Python error, but as you might guess from looking at
the script, the whole $SERVER_NAME piece is probably wrong. I thought maybe
I could do something like this...

*os.system('rosh -n', servername, '-l $LOGNAME')*

But of course os.system allows exactly one argument, and not three.

This is where I'm stuck, and I've been digging into the books and examples
and forums and just not quite sure what to look for. I would have liked to
have completed the script without asking for help, but nothing quite seems
to fit what I'm doing.

Any suggestions or guidance would be highly appreciated. Thanks!

K
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090107/d4024e4a/attachment.htm>


More information about the Tutor mailing list