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 |
Post your shell script in it's entirety.
Also you should not have the script in the /tmp/ directory... |
Quote:
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 |
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 ..............~..Connected. Connected. Disconnected. ----------------------------------- I have since created the following script which I would like cron to run #!/bin/sh LOGDATE=`data +%y%m%d` LOGFILE=/tmp/ttyS0.$LOGDATE 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> /bin/sh cu: End of file on terminal Connected. Connected. Disconnected. ----------------------------- 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 Tcore |
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 |
sleep
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. |
All times are GMT -5. The time now is 06:35 AM. |