Re: [BangPypers] Help On Paramiko

2012-06-18 Thread Noufal Ibrahim

Fabric is a library built on paramiko that gives you abstractions so
that you don't have to worry about things at such a fine grained
level. Perhaps you should try using that.

 writes:

> Howdy All,
>
> I am trying to use paramiko to automate logging in to remote unix machines 
> and executing some commands there.
> When I normally do ssh from my linux machine (with Python 2.6) to this 
> machine a different '>' prompt comes. It's a device specific custom prompt.
> After I run 'enable' command here, a new prompt opens up. '#' which is also 
> custom prompt.
> Then I need to run 'configure terminal' there. And then some more device 
> specific commands.
>
> i.e.
> {{{
> Linux # Ssh ad...@xx.xx.xx.xx
>
> Ø  Enable
> # configure terminal
> # 
> }}}
>
> Can this be done using paramiko?
> I tried with:
>
> {{{
> import paramiko
>
> client = paramiko.SSHClient()
> client.load_system_host_keys()
> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
> client.connect('xx.xx.xx.xx', username='admin', password='')
> stdin, stdout, stderr = client.exec_command('enable')
> #stdin.write('configure t')
> print(stdout.readlines())
>
> }}}
> (There is no passwd for username admin.)
>
>
> o/p
> ['UNIX shell commands cannot be executed using this account.\n']
>
> Any suggestions?
>
> Thanks
> Nikunj
> ___
> BangPypers mailing list
> bangpyp...@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>

-- 
Cordially,
Noufal
http://nibrahim.net.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [BangPypers] re module help

2012-01-09 Thread Noufal Ibrahim
Ganesh Kumar  writes:

> Hi Guys,
>
> I have created regular expression with os modules, I have created file
> sdptool to match the regular expression pattern, will print the result.
> I want without creating file how to get required output, I tried but i
> didn't get output correctly, over stream.

You should use the subprocess module to deal with external commands.

>>> import subprocess
>>> s = subprocess.Popen(["head", "/etc/hosts"], stdout = subprocess.PIPE)
>>> hosts_head = s.stdout.read()
>>> print hosts_head
127.0.0.1   localhost

[...]

Use that get your output and then parse it with the regexp.


-- 
~noufal
http://nibrahim.net.in

The best cure for insomnia is to get a lot of sleep. -W. C. Fields
-- 
http://mail.python.org/mailman/listinfo/python-list