因此,我正在尝试创建一个cron作业,该作业将每天在网页上执行作业。
我的cron命令: 0 0 * * * / 1 wget -t 1 - “http://urlto.job/job9” - O - >>家/ password_reset_log.txt
所有这一切都有效,但是我正在尝试执行看似琐碎的任务,即在文本文件中为每个条目添加一个新行。
目前我得到:
{"error":0,"result":"Password reset email successfully sent to 0 users, 0 emails failed to send","jDateLastRun":"10 Jan 2018, 00:00:07","jHandle":"check_password_resets","jID":"9"}{"error":0,"result":"Password reset email successfully sent to 0 users, 0 emails failed to send","jDateLastRun":"10 Jan 2018, 00:00:07","jHandle":"check_password_resets","jID":"9"}
所以所有条目都在一行上。我想要的是:
{"error":0,"result":"Password reset email successfully sent to 0 users, 0 emails failed to send","jDateLastRun":"10 Jan 2018, 00:00:07","jHandle":"check_password_resets","jID":"9"}
{"error":0,"result":"Password reset email successfully sent to 0 users, 0 emails failed to send","jDateLastRun":"10 Jan 2018, 00:00:07","jHandle":"check_password_resets","jID":"9"}
所以所有条目都从一个新行开始(更容易阅读并查看哪些作业成功运行,哪些作业失败以及每次作业运行的结果)。
是否有一种简单的方法(可能在我的cron命令中添加一个参数)。
答案 0 :(得分:1)
使用| xargs echo
附加换行符。
您的参赛作品将如下所示:
0 0 * * */1 wget -t 1 - "http://urlto.job/job9" -O - | xargs echo >> home/password_reset_log.txt
当然,只有当您的网址每次只提供一行时,这才有效。
这里有大家享受的演示:
user@host:~$ echo -n "No newline"
No newlineuser@host:~$ echo -n "With newline" | xargs echo
With newline
user@host:~$