試圖輸出cronjobs列表,而不是用戶列表。 crontab -l
的原始輸出太髒了,我似乎無法清理它。我運行這個sudo script.sh
或su
然後運行它。我也嘗試過調用它sudo script.sh | grep -v no
。我很迷惑,爲什麼這不起作用:列出所有cronjobs,如果有任何沒有多餘的信息
#!/bin/bash
#Trying to show all cronjobs but no extraneous info
#
# This shows "no crontab for USER" for every USER without
# a crontab - I only want to see actual cronjobs, not a long
# list of users without crontabs
echo "Here is the basic output that needs manipulation:
"
for USER in `cat /etc/passwd | cut -d":" -f1`; do
crontab -l -u $USER
done
#
# grep -v fails me
# (grep'ing the output of the script as a whole fails also)
echo "
trying with grep -v no on each line:
"
for USER in `cat /etc/passwd | cut -d":" -f1`; do
crontab -l -u $USER | grep -v no
done
echo "
maybe with quotes around the no:
"
for USER in `cat /etc/passwd | cut -d":" -f1`; do
crontab -l -u $USER | grep -v "no"
done
# string manipulation - I can't even get started
echo "
And here I try to put the commmand output into a string so I can manipulate it further, and use an if/then/fi on the product:
"
for USER in `cat /etc/passwd | cut -d":" -f1`; do
STRING="$(crontab -l -u $USER | grep -v no)"
echo "STRING: $STRING"
done
BTW,有更簡單的方式來獲得代碼格式化正確這裏比在每行開頭的4位粘貼?我必須嘗試了40分鐘。不抱怨,只是問。
選擇(繪製)整個代碼塊並按下ctrl-K進行格式化。 – tripleee