Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Crontab挂起在管道、作用域或语法错误上_Bash_Awk_Cron_Pipeline - Fatal编程技术网

Bash Crontab挂起在管道、作用域或语法错误上

Bash Crontab挂起在管道、作用域或语法错误上,bash,awk,cron,pipeline,Bash,Awk,Cron,Pipeline,我有一个shell脚本,它可以像我的用户一样正常工作,在crontab中工作大约一半。但是,它只完成rm行,并挂在awk行上: #!/bin/bash get_listeners.pl > temp.txt #accesses my icecast admin page and puts some useful metrics in temp.txt date +\%s > unpaired.txt grep "Current Listeners" temp.txt | sed

我有一个shell脚本,它可以像我的用户一样正常工作,在crontab中工作大约一半。但是,它只完成rm行,并挂在awk行上:

#!/bin/bash

get_listeners.pl > temp.txt
#accesses my icecast admin page and puts some useful metrics in temp.txt

date +\%s > unpaired.txt
grep "Current Listeners" temp.txt | sed 's/[^0-9]//g' >> unpaired.txt
#first line of unpaired.txt is time, second line is number of listeners

sed '$!N;s/\n/ /' unpaired.txt >> data.dat
#combine the two lines and append it to the data file

rm unpaired.txt
#tidy up

A=$(($(date +\%s) - 86400)) | awk -v a=$1 '{if ($1 >= a) print $1,$2}' data.dat > data2.dat
#get variable of 24 hours ago; only copy lines from last 24 hours to new file

gnuplot < demo.plt
#make plot from data in new file
所有路径在crontab中都是显式的;我只是把它们移到这里来保持简洁

所有文件都设置为777,data.dat稳定构建,作业每分钟运行一次,但从不将数据迁移到该awk行中的第二个文件。如果有人能指出awk线路有什么问题,我几乎可以肯定这就是问题所在。变量不能在cron中管道化吗?谢谢。

24小时前获取变量;仅将过去24小时内的行复制到新文件

从评论来看,您可能想这样做:

A=$(($(date +\%s) - 86400))
awk -v a="$A" '$1 >= a{print $1,$2}' data.dat > data2.dat
awk线没有真正意义。为什么要用烟斗?您希望awk读取管道还是读取data.dat,或者两者都要?要读取管道,则必须在其中写入内容。A=$$date+\%s-86400不会将任何内容写入管道。