[Tutor] Opsware Global Shell Scripting

Kayvan Sarikhani ksarikhani at gmail.com
Wed Jan 7 23:50:12 CET 2009


On Wed, Jan 7, 2009 at 4:57 PM, spir <denis.spir at free.fr> wrote:

> Le Wed, 7 Jan 2009 16:04:28 -0500,
> "Kayvan Sarikhani" <ksarikhani at gmail.com> a écrit :
>
> > #!/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.
>
> > #!/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 issue is, when comparing the bash script to the python one, that
> $SERVER_NAME makes sense only
> for bash -- as well as $LOGNAME that you properly changed.
>
> > *os.system('rosh -n', servername, '-l $LOGNAME')*
>
> This goes on the right way. Actually, os.system's arg is a plain string. To
> construct it out of
> several substrings you have to use matching string operators (actually
> methods). To be explicit:
>
> string_shell_command = 'rosh -n' + servername + '-l $LOGNAME'
> or
> string_shell_command = 'rosh -n %s -l $LOGNAME' %servername
> and then:
> os.system(string_shell_command)
>
> Than, I'm not fully sure this will be enough unless $LOGNAME is an env
> variable known by the
> system (I don't know well linux yet). It seems to be, as it is not defined
> in your bash script.
>
> Denis


Ah, that makes sense...I didn't know we could devise our own commands in
strings like that. That helps me quite a lot, actually. Thank you very much,
Denis!

For the record, $LOGNAME works fine as a variable...it's a standard env
variable in Linux to display the current user's username. There's other ways
of getting it, but that seems to be the most exact from what I can gather.

Thanks again, when I make some progress or complete it (hopefully), I'll
post further.

Kayvan

PS - Sorry for the re-send, forgot to include the tutor list.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090107/2655faa3/attachment.htm>


More information about the Tutor mailing list