【发布时间】:2015-08-27 16:38:56
【问题描述】:
我正在开展一个项目,该项目包括一系列数据记录传感器,这些传感器通过 Java 应用程序将所有数据发送回 CSV 文件。手动运行时,.jar 文件和 .sh 文件都将打开应用程序并记录数据而不会出现问题。
此时,我需要每天早上 6 点重新启动程序,以便将 CSV 文件分割成 1 天的块。
这是我正在使用的 shell 脚本示例:
#!/bin/bash
cd /home/pi/Desktop/Weights/410510/
sudo java -jar weight.jar
这是我在 Crontab 中一直使用的:
0 6 * * * /home/pi/Desktop/./start410510 >/tmp/file_name.log 2>&1
我添加了用于调试的日志文件输出。该程序将运行,有时甚至会记录 1 个数据点,然后立即关闭。该程序通过用户在键盘上的干预或终端的物理出口手动关闭。 是否有可能是 crontab 正在输入导致程序关闭的内容?
这是允许关闭的程序部分:
System.out.print("\n\nPress any key to close...\n\n");
try {
System.in.read();
}
catch (IOException ex) {}
输出应如下所示,但包含整个 24 小时的数据点:
pi@raspberrypi ~/Desktop $ sudo java -jar weight.jar
Waiting for the Phidget Bridge to be attached...
Phidget Information
====================================
Version: 102
Name: Phidget Bridge 4-input
Serial #: 410510
# Bridges: 4
Setting the enable state of bridge 0 to true
Setting the gain of bridge 0 to 8
Setting the enable state of bridge 1 to true
Setting the gain of bridge 1 to 8
Setting the enable state of bridge 2 to true
Setting the gain of bridge 2 to 8
Setting the enable state of bridge 3 to true
Setting the gain of bridge 3 to 8
Setting the data rate to 1000
Press any key to close...
2015-08-27 11:39:29.05,1,7.6E-4
2015-08-27 11:39:29.252,2,0.002682
2015-08-27 11:39:29.46,3,-0.001937
2015-08-27 11:39:29.836,0,-5.36E-4
2015-08-27 11:39:30.044,1,8.2E-4
2015-08-27 11:39:30.252,2,0.002563
2015-08-27 11:39:30.468,3,-0.001922
2015-08-27 11:39:30.836,0,-4.77E-4
2015-08-27 11:39:31.044,1,7.3E-4
2015-08-27 11:39:31.252,2,0.002638
2015-08-27 11:39:31.468,3,-0.001952
2015-08-27 11:39:31.836,0,-4.32E-4
2015-08-27 11:39:32.044,1,7.3E-4
2015-08-27 11:39:32.252,2,0.002667
2015-08-27 11:39:32.468,3,-0.001878
2015-08-27 11:39:32.836,0,-4.92E-4
2015-08-27 11:39:33.044,1,6.41E-4
Turning off Phidget Bridge
相反,当程序通过 Crontab 运行时,日志文件的输出是这样的:
pi@raspberrypi /tmp $ more file_name.log
Waiting for the Phidget Bridge to be attached...
Phidget Information
====================================
Version: 102
Name: Phidget Bridge 4-input
Serial #: 410510
# Bridges: 4
Setting the enable state of bridge 0 to true
Setting the gain of bridge 0 to 8
Setting the enable state of bridge 1 to true
Setting the gain of bridge 1 to 8
Setting the enable state of bridge 2 to true
Setting the gain of bridge 2 to 8
Setting the enable state of bridge 3 to true
Setting the gain of bridge 3 to 8
Setting the data rate to 1000
Press any key to close...
2015-08-27 09:16:03.086,2,-1.94E-4
Turning off Phidget Bridge
【问题讨论】:
标签: java shell jar raspberry-pi raspbian