12

I have a problem executing a cron process to check current CPU use in my server.

My script start with:

top -c -n 1 -u www-data > /tmp/kill-cpu

I can execute without problem in console, but in cron I get

top: failed tty get

If I use the -b option to top

top -b -n 1

I get

'dumb': unknown terminal type.

I'm using xterm as TERM

Thanks for your help :)
Lito.

SOLUTION: I was able to solve the problem with:

ln -s /lib/terminfo/d/dumb /usr/share/terminfo/d/dumb
Lito
  • 265
  • 2
  • 3
  • 10

1 Answers1

9

You can try something like:

TERM=vt100 top -b -n 1

This will set the TERM variable to execute with the "top" command.

But your underlying problem is that your termcap database is incomplete or broken. I don't have a Debian machine to look at, but on an Ubuntu box, the "dumb" termcap info is in the file /usr/share/terminfo/d/dumb. This file is part of the ncurses-base package on Ubuntu 8.04 and 10.04. On RHEL, it's part of the ncurses package. Perhaps your installation is simply missing this file?

cjc
  • 24,533
  • 2
  • 49
  • 69
  • Yep, I was just digging around in the top source and if you choose batch mode it sets TERM to dumb. – user9517 Aug 24 '11 at 13:56
  • No, problem is not solved with this command: root@server:~# TERM=vt100 top -b -n 1 'dumb': unknown terminal type. root@server:~# ls /usr/share/terminfo/d/dumb ls: /usr/share/terminfo/d/dumb: No such file or directory I have 286 files in /usr/share/terminfo/d/ folder – Lito Aug 24 '11 at 14:09
  • OK, you'll have to figure out why the /usr/share/terminfo/d/dumb file is missing from that system. As noted, I don't have a Debian box to play with. On Ubuntu, the package that provides that file is "ncurses-base". Perhaps you can do "apt-cache search dumb" to figure out which package you'll need on Debian. I suppose you can also copy the file from your working Debian box, but it'd be better to figure out if a package is missing or broken. – cjc Aug 24 '11 at 14:32
  • Yes, apt-cache search dumb | grep term = ncurses-base but installing/reinstalling the package don't solve my problem. In my other (development) Debian 6 server (same version as production) I can execute "top -b" without problems and I haven't this dumb term file... – Lito Aug 24 '11 at 14:51
  • Run something like "strace top -b -n 1 2>&1 |grep term". This will show you the terminfo files that the "top" command is accessing. Do this on the box everything is working on, and the box that it's not working on. I just ran it on a RHEL box, and it looks for terminfo first in ~/.terminfo/d/dumb. Possibly, the user executing the cron on the other box has that file. If not, "strace" will show what the "top" command is actually doing. – cjc Aug 24 '11 at 16:55
  • Ok! In the development server perform the search in /root/.terminfo, /etc/terminfo/d/dumb, /lib/terminfo/d/dumb but in production server perform the search in /root/.terminfo/d/dumb, /usr/share/terminfo/d/dumb (this not exists). The /etc/terminfo/README explain: This directory is for system-local terminfo descriptions. By default, ncurses will search this directory first, then /lib/terminfo, then /usr/share/terminfo. but it's incorrect! isn't looking in /lib/terminfo/d/dumb (that exists in both servers). – Lito Aug 24 '11 at 19:16
  • With a "ln -s /lib/terminfo/d/dumb /usr/share/terminfo/d/dumb" I can get execute the command :) – Lito Aug 24 '11 at 19:16
  • Just wanted to add, the `-b` did it for me. I don't have `/usr/share/terminfo/d/dumb` on my system and was getting `top: failed to get tty` error message when running `top -n 1 > output_file.txt` I added `-b` for batch mode and everything began working for me. – harperville Mar 21 '14 at 12:16