我的shell脚本在从终端运行时运行正常(例如./postdata.sh),但是从CRON运行时它不起作用。我已经确认了PATH并使用完整路径来调用shell脚本。我也为cURL命令尝试了几种方法而没有任何改变。
shell脚本(postdata.sh)从OWFS文件中提取小数值,并将数据发布到接收URL编码值的Google脚本并将其放入Google电子表格中。我已经研究过将数据发布到Google电子表格的其他方法,但认为这是最简单的方法;如果cron工作可行。
root@onewire:/home/1wire_admin# cat postdata.sh
#!/bin/bash
urladdress="https://script.google.com/macros/s/AKfycbyBKdbVyVH2LlMQptNlMiF2KkRn/exec"
reeftemp=$(cat /home/1wire/1F.58D803000000/aux/28.C4C229070000/temperature)
if [ -n $reeftemp ]; then
# remove whitespace
reeftemp="$(echo -e "${reeftemp}" | sed -e 's/^[[:space:]]*//')"
postdata="temp=$reeftemp"
urladdress2=$urladdress"?"$postdata
echo "url2 = $urladdress2"
# Example URL=https://script.google.com/macros/s/AKfycbyBKdbVyVH2LlMQptNlMiF2KkRn/exec?temp=98.3
curl -G -L "$urladdress2"
fi
root@onewire:/home/1wire_admin#
crontab的:
SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/
*/5 * * * * /home/1wire_admin/get1wire.sh 1 >/dev/null 2>&1
*/5 * * * * /home/1wire_admin/postdata.sh
答案 0 :(得分:0)
不确定如何修复它......但是,它正在发挥作用。因为我使用cURL来获取某些东西,它可能只是有一个转储标准输出的地方吗?
我没有更改postdata.sh中的任何内容
我知道Google Scripts会执行重定向,并由#34; loading"返回的窗口而不是显示网页中的帖子数据的重定向页面而不是" loading"等待重定向页面被提供的页面。
这是我将crontabs改为
的内容*/5 * * * * /home/1wire_admin/postdata.sh >/home/1wire_admin/postdata.out 2>&1
输出:(postdata.out)
url2 = https://script.google.com/macros/s/AKfycbyBKdbVyVH2LlMQpz9LaFos/exec?temp=79.5875
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
100 2805 0 2805 0 0 1542 0 --:--:-- 0:00:01 --:--:-- 1578
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org">
<meta name="gwt:property" content="locale=en">
<style type="text/css">
html,body {margin: 0; padding: 0; height: 100%;}.loading-text {background: url(gwt/images/spin-wait.gif) no-repeat; font-size: 16px; font-weight: bold; margin: 16px 0 16px 40px; padding-left: 22px;}.loading-box {background-color: white; border: 1px solid #ACACAC; border-bottom-color: #999; box-shadow: 0 4px 16px rgba(0,0,0,0.2); margin-top: -25px; margin-left: -100px; padding: auto; position: absolute; top: 50%; left: 50%; width: 200px; height: 50px; z-index: 16777272;}.loading-glass-panel {-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=30 ); filter: alpha(opacity = 30); opacity: 0.3; background-color: #999; display: block; position: absolute; width: 100%; height: 100%; z-index: 16777271;}
</style>
<script type="text/javascript">
var startTime = new Date().getTime(); var tzPointsJson = "[1109635200000,1128902400000,1130657000000,1143333000000,1143806400000,1145000000000,1146380000000,1152489600000,1159800000000,1159500000000,1162095000000,1162075000000,1162105500000]"; var libId = "M6-SQ4FDCwGJ10HMl1cAg2dMtQJv3mDbG"; var payload = "{\x22types\x22:{\x22u892486473779\x22:\x22Label\x22,\x22u892486473778\x22:\x22VerticalPanel\x22},\x22libId\x22:\x22M6-SQ4FDCwGJ10HMl1cAg2dMtQJv3mDbG\x22,\x22id\x22:\x22u892486473777\x22,\x22title\x22:\x22\x22,\x22commands\x22:[{\x22args\x22:[],\x22cmd\x22:\x22VERTICALPANEL\x22,\x22id\x22:\x22u892486473778\x22},{\x22args\x22:[\x22temp 79.5875\x22],\x22cmd\x22:\x22LABEL2\x22,\x22id\x22:\x22u892486473779\x22},{\x22args\x22:[{\x22id\x22:\x22u892486473779\x22}],\x22cmd\x22:\x22ADD\x22,\x22id\x22:\x22u892486473778\x22},{\x22args\x22:[{\x22id\x22:\x22u892486473778\x22}],\x22cmd\x22:\x22ADD\x22,\x22id\x22:\x22u892486473777\x22}],\x22sMode\x22:false}"; var _tok = ""; var serviceId = "AKfycbyBKdbVyVH2LlMQptNlMiF2KkRnfaQmjz9LaFos-u-K3VG1h1Bi"; var _sd = true; var _aurg = false; var _ea = false; var _up = '\/macros\/s\/AKfycbyBKdbVyVH2LlMQptNlMiF2KkRnfaQmjz9LaFos-u-K3VG1h1Bi'; var standardsMode = false; var _atok = "";var _MF={0:true,5:true,8:30000,10:"https://console.developers.google.com",12:"https://script.google.com/macros/srvStatic/rpc_relay.html",13:"https://docs.google.com/picker",14:"jeffrey.engelbrecht@gmail.com",15:"https://script.google.com/macros"};
</script>
<script type='text/javascript' src=
'gwt/googleappsscripts_userapp.nocache.js'>
</script>
<script type='text/javascript' src='//www.google.com/jsapi'>
</script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages':['corechart', 'controls', 'annotatedtimeline']});
</script>
<title></title>
</head>
<body>
<div class="loading-glass-panel" id="loading-glass-panel"></div>
<div class="loading-box" id="loading-box">
<div class="loading-text" id="loading-text">Loading...</div>
</div>
</body>
</html>