WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [SOLVED] Error "System has no more ptys." when using "expect" and "spawn"  (Read 21190 times)

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Update 2012-12-14 1807:   Changed subject to better reflect the issue.  Original Subject was
       The system has no more ptys.  Ask your system administrator to create more.
  Marked as [SOLVED] since the functionality now works (with sudo).


I'm trying to use an "expect script to send a simple command to a remote box via ssh.  The script looks like this:
Code: [Select]
#!/usr/local/bin/expect
# whack871 - log in to the cisco 871 and warm boot it entirely under script
#            control.
#

# set Variables from arguments
set ipaddr [lrange $argv 0 0]
set user [lrange $argv 1 1]
set password [lrange $argv 2 2]
set command [lrange $argv 3 3]
#
set arg1 [lrange $argv 4 4]
set timeout -1
#
# connect to remote ssh server (ipaddr) with given command to execute
spawn ssh $user@$ipaddr $command $arg1
match_max 100000
#
# Look for password prompt
expect "*?assword:*"
#
# Send password aka $password
send -- "$password\r"
#
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof

and is invoked like this:
Code: [Select]
whack871 <IP ADDRESS> <USERNAME> <PASSWORD> <COMMAND>
with command in quotes if it contains spaces.

but it results in this:
Code: [Select]
spawn ssh tc@192.168.0.97 xtrlock
The system has no more ptys.  Ask your system administrator to create more.
    while executing
"spawn ssh $user@$ipaddr $command $arg1"
    (file "/home/tc/bin/whack871" line 18)

Under Cygwin on Windows Server 2008 R2, I can use this to warmboot my router.

Under Core 4.7.1, I cannot use this to send a command to another Core 4.7.1 box.  Booting the local box with the multivt boot code does not seem to help.

I have openssh.tcz, expect.tcz and tcl.tcz loaded and I can ssh to the remote box.

Does anyone know how to add more ptys ?


« Last Edit: December 14, 2012, 05:09:22 PM by Lee »
32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #1 on: December 01, 2012, 06:37:18 PM »
Try the boot code 'pty.legacy_count=32'
---- Edit ----
I tried it.  It looks like legacy ptys are not enabled in the kernel.
« Last Edit: December 01, 2012, 06:50:15 PM by gerald_clark »

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #2 on: December 01, 2012, 07:23:59 PM »
Thanks gerald_clark.

I was hoping for a simple boot code solution and it looks like that would have been it.

I'll look for a work around using something other than "spawn" - maybe something with exec and redirection.  If that doesn't work, is there any down-side that you know of to enabling legacy ptys in the kernel?
32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #3 on: December 01, 2012, 08:32:13 PM »
What is output of
Code: (bash) [Select]
cat /proc/sys/kernel/pty/maxand of
Code: (bash) [Select]
watch -n 1 cat /proc/sys/kernel/pty/nrjust at the moment you get the error?


"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #4 on: December 01, 2012, 09:54:36 PM »
cat /proc/sys/kernel/pty/max

says 4096


watch -n 1 cat /proc/sys/kernel/pty/nr

shows an unchanging  2

32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #5 on: December 01, 2012, 10:26:54 PM »
Could you check for same on target machine?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #6 on: December 02, 2012, 12:01:59 AM »
On the target machine it is pretty much the same, except

watch -n 1 cat /proc/sys/kernel/pty/nr

shows 6

This number reflects the number of terminal windows open - it goes up as I open additional ssh sessions - which is really what I want the expect script to do anyhow. I wonder if I can replace that spawn command with something else.

When I run the watch command on the remote box and run the expect script on the remote box, it is exactly as when I run them on the local box.

When I run the watch command on the remote box and the expect script on the local box, the watched value still does not change.
32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #7 on: December 02, 2012, 04:50:48 AM »
Expect should work fine with current PTYs. In fact, when I run your script here, it works as is.

I wonder if something is changing your permissions, on the host where you run expect. What's your permissions for /dev/ptmx and /dev/pty?
The only barriers that can stop you are the ones you create yourself.

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #8 on: December 02, 2012, 10:01:24 AM »
Code: [Select]
tc@apollo:~$ ls -l /dev/ptmx /dev/pty
ls: /dev/pty: No such file or directory
crw-rw-rw-    1 root     staff       5,   2 Dec  2 09:13 /dev/ptmx
tc@apollo:~$
tc@apollo:~$
tc@apollo:~$ ls -l /dev/ptmx /dev/pty?
ls: /dev/pty?: No such file or directory
crw-rw-rw-    1 root     staff       5,   2 Dec  2 09:13 /dev/ptmx
tc@apollo:~$

This is with the multivt boot code that I added in yesterday:
Code: [Select]
tc@apollo:~$ cat /proc/cmdline
quiet host=cruzr0 noutc tz=GMT+5 tce=LABEL=cruzr0/boot/core4.7.1/tce waitusb=30:LABEL=cruzr0 multivt

32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #9 on: December 02, 2012, 11:17:51 AM »
Typo, /dev/pts not pty.
The only barriers that can stop you are the ones you create yourself.

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #10 on: December 02, 2012, 01:30:34 PM »
Ok then.  I was a little worried for a minute there.  :)

Code: [Select]
tc@apollo:~$ ls -l /dev/ptmx /dev/pts
crw-rw-rw-    1 root     staff       5,   2 Dec  2 11:27 /dev/ptmx

/dev/pts:
total 0
crw-------    1 tc       staff     136,   0 Dec  2 11:27 0
c---------    1 root     root        5,   2 Dec  1 09:54 ptmx
tc@apollo:~$

The mention of permissions gave me the idea to try the whole thing using sudo... and that worked, though I had to tweak my script a bit to be able to pass arguments to the remote command.

Still, it seems like it ought to be able to do this as non-root.
32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #11 on: December 02, 2012, 01:42:53 PM »
Sorry, I mean the pts dir itself - "ls -lhd /dev/pts".
The only barriers that can stop you are the ones you create yourself.

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #12 on: December 02, 2012, 02:09:53 PM »
Code: [Select]
tc@apollo:~$ ls -lhd /dev/pts
drwxr-xr-x    2 root     root           0 Dec  1 09:54 /dev/pts/
tc@apollo:~$

Looks like only root can write to the directory...
32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #13 on: December 02, 2012, 02:28:20 PM »
Why would you want to write to that directory?

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: The system has no more ptys. Ask your system administrator to create more.
« Reply #14 on: December 02, 2012, 03:39:41 PM »
So it seems like that error msg is misleading and comes down to a permission issue.

BTW, just wondering, have you considered key authentification rather than using password?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)