Discussion:
su: must be run from a terminal
Eri Ramos Bastos
2009-11-09 00:47:16 UTC
Permalink
Hello, List.

I'm trying to run this: http://pastebin.com/me01a0c4

And what I get is:

$ ./test.py
su: must be run from a terminal

I tried to add the line bellow after the connection is established,
without luck:

client.invoke_shell(term='xterm', width=80, height=24)

I get no errors, but nothing returns at the stdout as well.

I'm trying to understand how I should be doing it, but since I'm a
sysadmin (not a programmer) most of the documentation looks like greek
for me.

Any hints, please?

Regards,
Eri Ramos Bastos
Sergio Tocalini Joerg
2009-11-09 00:11:37 UTC
Permalink
Post by Eri Ramos Bastos
Hello, List.
I'm trying to run this: http://pastebin.com/me01a0c4
$ ./test.py
su: must be run from a terminal
I tried to add the line bellow after the connection is established,
client.invoke_shell(term='xterm', width=80, height=24)
I get no errors, but nothing returns at the stdout as well.
I'm trying to understand how I should be doing it, but since I'm a
sysadmin (not a programmer) most of the documentation looks like greek
for me.
Any hints, please?
Regards,
Eri Ramos Bastos
_______________________________________________
paramiko mailing list
http://www.lag.net/cgi-bin/mailman/listinfo/paramiko
Hello,

I'm use paramiko with sudo too, with this function (note: this function
i got before i don't remember when, but i modify to work with sudo, and
this really works.):

def execute(self, command):
channel = self._transport.open_session()
channel.exec_command(command)
if command.startswith("sudo"):
channel.send(self.password + "\n")
output = channel.makefile('rb', -1).readlines()
if output:
return output
else:
return channel.makefile_stderr('rb', -1).readlines()

If you have any suggestion or doubt please let me know.

Regards
--
Larry loves Gentoo (Linux)

______________________
< Have you mooed today? >
-----------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
|| --------w |
|| ||

*****************************************
*****************************************
* GNU/Linux user #413468
* blog.sergiotocalini.com.ar
*****************************************
* MiWiki (Misiones Wiki)
* www.miwiki.org.ar
*****************************************
Sergio Tocalini Joerg
2009-11-09 00:13:00 UTC
Permalink
Post by Eri Ramos Bastos
Hello, List.
I'm trying to run this: http://pastebin.com/me01a0c4
$ ./test.py
su: must be run from a terminal
I tried to add the line bellow after the connection is established,
client.invoke_shell(term='xterm', width=80, height=24)
I get no errors, but nothing returns at the stdout as well.
I'm trying to understand how I should be doing it, but since I'm a
sysadmin (not a programmer) most of the documentation looks like greek
for me.
Any hints, please?
Regards,
Eri Ramos Bastos
_______________________________________________
paramiko mailing list
http://www.lag.net/cgi-bin/mailman/listinfo/paramiko
sorry I don't know if I was answer you question but with this function
you can rudo commands with sudo and may be it's the same =)

Regards
--
Larry loves Gentoo (Linux)

______________________
< Have you mooed today? >
-----------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
|| --------w |
|| ||

*****************************************
*****************************************
* GNU/Linux user #413468
* blog.sergiotocalini.com.ar
*****************************************
* MiWiki (Misiones Wiki)
* www.miwiki.org.ar
*****************************************
Eri Ramos Bastos
2009-11-09 10:27:41 UTC
Permalink
Thank you, Sergio.

Unfortunately I don't have (nor can have) sudo running on the servers
where I need to run that.
I must use a pure and simple "su".

This code is part of a larger script I'm using to migrate users from a
legacy environment to a new one, with proper tools like sudo
installed.

Thanks, anyway.

[]'s
Eri Ramos Bastos

On Sun, Nov 8, 2009 at 8:13 PM, Sergio Tocalini Joerg
Post by Sergio Tocalini Joerg
Post by Eri Ramos Bastos
Hello, List.
I'm trying to run this:  http://pastebin.com/me01a0c4
$ ./test.py
su: must be run from a terminal
I tried to add the line bellow after the connection is established,
client.invoke_shell(term='xterm', width=80, height=24)
I get no errors, but nothing returns at the stdout as well.
I'm trying to understand how I should be doing it, but since I'm a
sysadmin (not a programmer) most of the documentation looks like greek
for me.
Any hints, please?
Regards,
Eri Ramos Bastos
_______________________________________________
paramiko mailing list
http://www.lag.net/cgi-bin/mailman/listinfo/paramiko
sorry I don't know if I was answer you question but with this function
you can rudo commands with sudo and may be it's the same =)
Regards
--
Larry loves Gentoo (Linux)
 ______________________
< Have you mooed today? >
 -----------------------------------
       \   ^__^
        \  (oo)\_______
           (__)\              )\/\
                  || --------w |
                  ||             ||
*****************************************
*****************************************
* GNU/Linux user #413468
* blog.sergiotocalini.com.ar
*****************************************
* MiWiki (Misiones Wiki)
* www.miwiki.org.ar
*****************************************
Eric Noulard
2009-11-09 12:50:41 UTC
Permalink
Post by Eri Ramos Bastos
Hello, List.
I'm trying to run this:  http://pastebin.com/me01a0c4
$ ./test.py
su: must be run from a terminal
I tried to add the line bellow after the connection is established,
client.invoke_shell(term='xterm', width=80, height=24)
I get no errors, but nothing returns at the stdout as well.
You should use the object returned by invoke_shell for further interaction:

shell = client.invoke_shell(term='xterm', width=80, height=24)

and then

shell.sendall('su -c "cat /var/spool/cron/%s" \n' % SOURCE_CLIENT_NAME )
shell.sendall("root_password" + '\n')

result = shell.recv(1024)

result should contain more or less what you expect.

shell is a paramiko.Channel thus you can see which methods
you can call on this kind of object:
http://www.lag.net/paramiko/docs/paramiko.Channel-class.html
Post by Eri Ramos Bastos
I'm trying to understand how I should be doing it, but since I'm a
sysadmin (not a programmer) most of the documentation looks like greek
for me.
Sys Admin and programmers are not living far away from each other.
You'll be soon be speaking Greek fluently :-)
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
Eri Ramos Bastos
2009-11-09 14:49:51 UTC
Permalink
Thanks, Eric.
I'm still struggling, though.
Post by Eric Noulard
shell.sendall('su -c "cat /var/spool/cron/%s" \n' % SOURCE_CLIENT_NAME )
shell.sendall("root_password" + '\n')
result = shell.recv(1024)
result should contain more or less what you expect.
print result returns:

su -c "cat /var/spool/cron/user" \r\nroot_password\r\n

I tried to increase the recv size to 4096 but got nothing.

Also I checked the other recv_* methods and they don't look to return
the command. This recv looks like the right one, but it comes out
empty.
Post by Eric Noulard
Sys Admin and programmers are not living far away from each other.
You'll be soon be speaking Greek fluently :-)
Yeah... I started use Python due to bash script limitations and I loved it. ;)
Still having problems like understanding documentation, but I'll learn
sooner or latter.

[]'s
Eri Ramos Bastos
Eric Noulard
2009-11-09 15:46:44 UTC
Permalink
Post by Eri Ramos Bastos
Thanks, Eric.
I'm still struggling, though.
could you try
shell = client.invoke_shell(term='vt100', width=80, height=24)

i.e. 'vt100' instead of 'xterm'.

Then just after that could you try reading with

print shell.recv(1)

until there is nothing to be read. Just after you request a shell
you should get output from it BEFORE sending anything just as
you do when you login into any system with a login shell.

If you do not read this first output
your pty input may be stalled because
you did not read enough output from it first.

You can do this in an interactive python shell in order to experiment
more easily.
Post by Eri Ramos Bastos
Post by Eric Noulard
Sys Admin and programmers are not living far away from each other.
You'll be soon be speaking Greek fluently :-)
Yeah... I started use Python due to bash script limitations and I loved it. ;)
Still having problems like understanding documentation, but I'll learn
sooner or latter.
Sure you will.
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
Eri Ramos Bastos
2009-11-09 19:31:59 UTC
Permalink
Got it working.

The problem seems to be related to the server slow response. I fixed
by doing this:

while not shell.recv_ready():
time.sleep(1)

data = shell.recv(2048)
print data

Thanks a lot!

[]'s
Eri Ramos Bastos
Post by Eric Noulard
Post by Eri Ramos Bastos
Thanks, Eric.
I'm still struggling, though.
could you try
shell = client.invoke_shell(term='vt100', width=80, height=24)
i.e. 'vt100' instead of 'xterm'.
Then just after that could you try reading with
print shell.recv(1)
until there is nothing to be read. Just after you request a shell
you should get output from it BEFORE sending anything just as
you do when you login into any system with a login shell.
If you do not read this first output
your pty input  may be stalled because
you did not read enough  output from it first.
You can do this in an interactive python shell in order to experiment
more easily.
Post by Eri Ramos Bastos
Post by Eric Noulard
Sys Admin and programmers are not living far away from each other.
You'll be soon be speaking Greek fluently :-)
Yeah... I started use Python due to bash script limitations and I loved it. ;)
Still having problems like understanding documentation, but I'll learn
sooner or latter.
Sure you will.
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
Loading...