iT邦幫忙

第 12 屆 iThome 鐵人賽

0
自我挑戰組

30天菜鳥學 Linux 系列 第 50

第 50 天 - 學習 crontab 工作排程 - 解決遇到的菜鳥問題

遇到問題 : 想要測試 1 分鐘創建一個檔案,但一直沒有效果

crontab -e
*/1 * * * * name=$(date +"%Y%m%d%H%M%S");name+='.txt';touch /home/test/$name

嘗試1 : 查詢 log
結果 : 沒發現有用的訊息

test@test:~$ grep cron /var/log/syslog
Oct 23 01:17:41 test crontab[7961]: (test) BEGIN EDIT (test)
Oct 23 01:18:33 test crontab[7961]: (test) END EDIT (test)

嘗試2 : 聽從網友跟鳥哥建議:

建議改成呼叫 bash 方式

『指令下達時,最好使用絕對路徑,這樣比較不會找不到執行檔喔!』

結果 : 解決了問題

test@test:~$ vim testbash.sh

#!/bin/bash
name=$(date +"%Y%m%d%H%M%S");name+='.txt';touch /home/test/$name

test@test:~$ crontab -e
* * * * * bash /home/test/testbash.sh

image-20201023133651556

遇到問題 : sudo vim /etc/crontab 沒有效果

使用命令 grep cron /var/log/syslog

發現是錯誤 username 問題

image-20201023085520894

crontabe -e 不一樣,要記得輸入使用者

image-20201023135820471

小插曲

學會 vim 批量刪除

一直都是 backspace 按到底 XD

今天終於忍不住去 google,才知道 :1,$d 可以批量刪除全部文本,按兩次 d刪除游標所在的行

每日一句

有時候不是沒辦法,只是真的懶得去 google,一直死撐


上一篇
第49天-學習 crontab 工作排程 Part 2 - 認真學 crontab 表達式
下一篇
第 51 天 - 研究 shell 解釋器 - part1
系列文
30天菜鳥學 Linux 59
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言