用於啟動無 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,現在它可以工作了。

相關內容