
我想用 Crontab 安排每週備份,但我以前從未使用過它,所以我想從一個簡單的命令開始測試它,例如用 gedit 打開一個文字檔案。
我遵循了這個指南:
https://help.ubuntu.com/community/CronHowto
sudo crontab -e
我在終端機中獲取文件並添加以下內容:
m h dom mon dow command
34 12 * * * /usr/bin/gedit /home/KEN/Desktop/ImaTXT
當我儲存並安裝這個新的 crontab 時,時間是 12:32:
crontab: installing new crontab
我檢查它是否已保存:
sudo crontab -l
兩分鐘過去了,什麼也沒打開。
我究竟做錯了什麼?
謝謝凱維,它成功了。
答案1
您應該指定$DISPLAY
環境變數和使用者(可能是肯在你的情況下)。
$ sudo crontab -e -u user
m h dom mon dow command
34 12 * * * export DISPLAY=:0 && /usr/bin/gedit /home/KEN/Desktop/ImaTXT