Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the Ubuntu 10.04.4LTS, and have Ganglia installed in my computer.

I used to get the Gmetad data by typing:

telnet localhost 8651 > /test/test.txt

or made a .sh file to run it. After this I want to get Gmetad data periodically. I try Crontab. After some simple test I am sure that the Crontab works in my Ubuntu. However, when I try to make crontab get the data by setting like this:

*/5 * * * * root sudo telnet localhost 8651 > /test/test.txt

The output file will be incomplete, for example:

3263  2012-07-13 09:28 FromCrontab.txt
44833 2012-07-13 08:14 CorrectOne.txt

The CorrectOne.txt file contain 44833 chars, but the output file from Crontab contains only 3263 chars.

I've tried to solve this by using tee:

sudo telnet localhost 8651 | tee -i /test/test.txt

or change the SHELL:

SHELL=/bin/sh or SHELL=/bin/bash

neither one could help.

I'm new to Ubuntu and not I'm not familiar with crontab or telnet. Hoping someone could help me solve this problem or give me some direction for studying.


share|improve this question
up vote 1 down vote accepted

Use nc:

 The nc (or netcat) utility is used for just about anything under the sun
 involving TCP or UDP.  It can open TCP connections, send UDP packets,
 listen on arbitrary TCP and UDP ports, do port scanning, and deal with
 both IPv4 and IPv6.  Unlike telnet(1), nc scripts nicely, and separates
 error messages onto standard error instead of sending them to standard
 output, as telnet(1) does with some.

To install it, type sudo apt-get install netcat-openbsd.

Something like this should be a good replacement for your telnet line (this assumes you don't have to send or type anything to get the data; sorry, I'm unfamiliar with ganglia):

nc localhost 8651 > /test/test.txt

And on your /etc/crontab:

* * * * * root nc localhost 8651 > /test/test.txt

Note that if you're running this as root, then you don't need sudo. Indeed, even as a normal user, you should not need to use sudo to run nc. For security reasons I suggest you avoid using root or sudo unless strictly necessary.

share|improve this answer
Thanks for your help. The Netcat really gives a better and clean output data. But when I put the scripts on crontab, it still output a incomplete file. I was wondering the problem comes from Telnet, after this I am more confused... And thanks to your advice about security concern. I'm really new to Ubuntu and trying to get a better understanding about this. Thanks again :) – James Jul 13 '12 at 2:48
I found the answer. add a -q 10 option after nc will solve the problem! Thanks again :) – James Jul 13 '12 at 4:23
The other issue you faced was trying: '.. root sudo telnet ..'. You need to remove sudo, as this requires interaction (a user to type a password) and should not be used in crontab. – david6 Jul 13 '12 at 8:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.