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提取cron表达式_Bash_Shell_Cron - Fatal编程技术网

Bash crontab提取cron表达式

Bash crontab提取cron表达式,bash,shell,cron,Bash,Shell,Cron,当我执行crontab-l时,我可以看到我的所有作业 56 12 3 2 * /usr/bin/python3 /home/pi/Saqib/RaspBerryPiAdhan/www/commands/player.py "https://server6.mp3quran.net/akdr/001.mp3" "Office Ustairs speaker" >> .error.log 2>&1 # Al-Fatiha - [Verses 7] 56 12 * * *

当我执行crontab-l时,我可以看到我的所有作业

56 12 3 2 * /usr/bin/python3 /home/pi/Saqib/RaspBerryPiAdhan/www/commands/player.py "https://server6.mp3quran.net/akdr/001.mp3" "Office Ustairs speaker" >> .error.log  2>&1 # Al-Fatiha - [Verses 7]
56 12 * * * /files/python3 /home/pi/Saqib/RaspBerryPiAdhan/www/commands/player.py "https://server6.mp3quran.net/akdr/001.mp3" "Office Ustairs speaker" >> .error.log  2>&1 # Al-Fatiha - [Verses 7]
31 18 3 2 * /usr/bin/python3 /home/pi/Saqib/RaspBerryPiAdhan/www/commands/player.py "/static/media/azan5.mp3" "Office Ustairs speaker" # prayer_isha
无论如何,我只能提取“表达式”吗

我需要像这样出去

56 12 3 2 * 
56 12 * * * 
31 18 3 2 * 
这应该起作用:

crontab -l |awk '{NF=5}1'

这里您告诉awk,每行中的字段数为5,这导致打印前五列。

您可以使用以下方法

crontab -l | sed 's/  *\/.*//'
它用空字符串替换斜杠(需要转义,
\/
)后的所有内容(
*
),包括斜杠及其前面的空格(
*

如评论中所述,此解决方案根本不可靠,因为它依赖于问题中示例特有的格式。

Cut也应该有效

crontab -l | cut -d ' ' -f-5

我明白了,}后面的“1”是什么?明白了“每四小时”的表达式是
0*/4***
。常规邮件警报可能是
0 8***echo“起床时间”|邮件me@host
。两者都会导致这个命令失败哦,我不知道crontab的输出格式,所以我的问题是基于OP中显示的示例。不过,感谢您指出这一点。