【问题标题】:Crontab runs but nothing happenscrontab 运行但没有任何反应
【发布时间】:2017-12-18 04:40:42
【问题描述】:

我想模拟一张壁纸幻灯片(图片来自unsplash.com)几乎与Windows 7 相同,但在Ubuntu 上。所以为此我决定使用unsplash-wallpaper。

我创建了一个 bash 脚本 .refresh-wallpaper.sh 并将其放入主目录:

#!/bin/bash
unsplash-wallpaper -r --dir "~/Pictures/wallpapers"

然后我安装一个 crontab:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * sh ~/.refresh-wallpaper.sh >/dev/null 2>&1

脚本由 crond 运行,但什么也没发生:

Dec 17 22:12:01 pcname CRON[11933]: (username) CMD (sh ~/.refresh-wallpaper.sh >/dev/null 2>&1)

..但它在通过终端手动启动时有效:

username@pcname:~$ sh .refresh-wallpaper.sh 
Request https://source.unsplash.com/random
Downloading [==================================================================]
✔︎ Image saved to /home/username/Pictures/wallpapers/wallpaper-photo-1511620356826-e2ed21a61991.jpg
Check it out.

我做错了什么?感谢您的互动!

EDIT1:之所以有效,是因为保存了新图像并将输出重定向到日志,但桌面上的壁纸没有检出。

【问题讨论】:

  • 只需通过调用bash -x ~/..sh > /tmp/log 来查看输出,而不是让整个事情静音。
  • 顺便说一句:sh 不是 bash。
  • @Pavel,感谢您的回复。它之所以有效,是因为保存了新图像并将输出重定向到日志,但壁纸没有检出。您有解决问题的想法吗?

标签: bash shell ubuntu cron


【解决方案1】:

我假设您脚本中的引号会阻止 ~ 在此行中的扩展:

unsplash-wallpaper -r --dir "~/Pictures/wallpapers"

我建议使用:

unsplash-wallpaper -r --dir "$HOME/Pictures/wallpapers"

【讨论】:

  • 但是为什么手动运行它会起作用?脚本也有引用问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-18
  • 2013-03-24
  • 2021-10-16
  • 2021-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多