Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.


  Search this Thread
Old 03-06-2005, 04:24 PM   #1
LQ Newbie
Registered: Mar 2005
Posts: 4

Rep: Reputation: 0
info to run "cu" command from cron

I am trying to create an automated process to capture information from a serial device connected to the COM port (ttyS0).

Using the command

cu –l /dev/ttyS0 –s 2400 dir | tee log_out

From the command line, I am able to connect to the device and see data scrolling on my screen. When I put this command in a shell script and have it run by cron, the log file that is created only contains “connected” and “disconnected” No data is captured in this file.

This is the cron entry which I have running by user uucp. I also tried user root but same problem.

10 * * * * /tmp/cmd_capture > /dev/null 2>&1

Does anyone know what I am doing wrong. and have any ideas how I can caputure the data at the serial
Old 03-10-2005, 12:55 PM   #2
Senior Member
Registered: Sep 2004
Location: Outlying D.C.
Distribution: Mandriva
Posts: 2,090

Rep: Reputation: 46
Post your shell script in it's entirety.

Also you should not have the script in the /tmp/ directory...
Old 03-11-2005, 01:26 AM   #3
Registered: Jan 2005
Location: Övik, Sweden
Distribution: MDK 10.1
Posts: 450

Rep: Reputation: 30
From the command line, I am able to connect to the device and see data scrolling on my screen
If you run that exact command, what ends up in the log_out file?
In the cron job you dump standard out and standard error to /dev/null. Perhaps "cu" writes to stderr instead of stdout.

Try abbreviating the command to "cu –l /dev/ttyS0 –s 2400 dir" and put
"/tmp/cmd_capture 2> /tmp/log_out 1> /dev/null" in cron.

- Peder

Last edited by bunnadik; 03-11-2005 at 01:29 AM.
Old 03-11-2005, 12:59 PM   #4
LQ Newbie
Registered: Mar 2005
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for your input.

With the serial device connected to the com port, and I run the command below

cu –l /dev/ttyS0 –s 2400 dir | tee log_out

I get the following in the log_out file, which is also what I see being displayed on my screen. Note that this is part of the data that I would like to capture or log automatically.

*** Reset reason: POWER ON ***

Performing Self-Tests:
Hardware version: PASS
External SRAM: PASS
External FLASH: PASS (Man= 0001, Dev= 22BA: AM29LV400B (4 MBit) )
Terminal IDs: PASS
Application Load: PASS


I have since created the following script which I would like cron to run

LOGDATE=`data +%y%m%d`
cu –s 2400 –l /dev/ttyS0 dir | tee $LOGFILE0

When I run the above script which I call capture_port, from the command line, a file is created and similar data as above is written to the file.
However when I run this script under cron (root or uucp user ) the only data I see in the log file is "connected" followed by "disconected"

The cron entry I have is

0,10,20,30,40,50 * * * * /etc/uucp/capture_port

Every time cron runs "capture_port" I receive this mail message from cron. I am concerned about the line. . cu:End of file on terminal

Date: Fri, 11 Mar 2005 07:30:00 -0500
From: root@localhost.localdomain (Cron Daemon)
To: root@localhost.localdomain
Subject: Cron <root@lager> /etc/uucp/capture_port
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>

cu: End of file on terminal
If I shorten the cu command in my script "cu -l /dev/ttyS0 -s 2400 dir" and modify the cron entry to be "/etc/uucp/cmd_capture 2> /tmp/log_out 1> /dev/null" then a file log_out is created and it contains only one line

cu: End of file on terminal

Any ideas on why I get this message. It seems that cu opens the ttyS0 port but it is expecting something to keep it open. What ever is required to keep the port open is not present so the port is closed

Old 03-12-2005, 06:03 AM   #5
Registered: Jan 2005
Location: Övik, Sweden
Distribution: MDK 10.1
Posts: 450

Rep: Reputation: 30
I assume this is a typo here: "LOGDATE=`data +%y%m%d`" (shoud be date, right?).
And you also have an ending zero in LOGFILE that is suspect.

Why do you " | tee $LOGFILE " ? "tee" splits the input so it goes to screen as well as the file, and in a
cron job you normally don't want anything to screen. Try using " > $LOGFILE " instead.

Also in your command line you have " –l /dev/ttyS0 –s 2400 " but in the script they're reversed.
I'm not familiar with "cu" but it might be picky about that.

BTW what is "dir" in the command line? That's usually an alias to 'ls'.

- Peder
Old 12-27-2018, 11:34 AM   #6
LQ Newbie
Registered: Dec 2005
Location: The Netherlands
Posts: 16

Rep: Reputation: 0

A bit late But I just ran into this myself. I hope this might save someone some time.

I have no deep knowledge of cron, but it seems it is piping to the command (`cu` in this case) and then quickly closing the pipe. `cu` behaves by stopping when stdin is closed, even when there could still be input. For example, you can make `cu` close after two second by running

sleep 2s | cu -l ... -s ...

This example also holds the solution for me. We can insert infinite sleep in crontab. This will ignore the closed pipe from cron and keep a pipe open infinitely to cu.

@reboot sleep infinite | cu -l ... -s ... | tee ...

Works for me.

Last edited by NoKnower; 12-28-2018 at 05:07 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
simple "echo > qbc" cron jobs doesn't run shole Linux - Newbie 3 09-23-2006 02:09 PM
"info" command is missing... netsoul Mandriva 4 03-15-2005 12:47 PM
How can I run the "cu" command under cron? tcore Linux - General 1 03-08-2005 07:45 AM
system("top") in a C program giving problems when the C prg is run by cron rags2k Programming 1 09-02-2004 03:25 PM > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 06:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration