用于启动无 IP 的 crontab 不起作用

用于启动无 IP 的 crontab 不起作用

我的网络服务器有问题。通常您通过 启动 No-IP-DUC sudo noip2。我尝试使用 cronjob 使其自动化。使用crontab -e,我创建了这个文件:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

@reboot cd /home/username/noip-2.1.9-1 && sudo noip2

它不起作用,我不知道为什么。如果有人能帮助我那就太好了。

答案1

而不是做

cd /home/用户名/noip-2.1.9-1 && sudo noip2

我宁愿执行“sudo crontab -e”以将 cronjob 添加为 root(并避免在 cronjob 内执行 sudo)。

另外我知道您想要执行 noip2 (位于 /home/username/noip-2.1.9-1 文件夹内)。所以我会将 cronjob 更改为

@reboot /home/username/noip-2.1.9-1/noip2

答案2

我找到了一个替代解决方案:我将路由器连接到 No-IP,现在它可以工作了。

相关内容