모두 볼 수 있는 방법이 있는 명령 또는 기존 스크립트입니다 let me a * NIX system& # 39 의 스케줄링된 cron 작업을 한 번에? # 39 i& 모두 포함할 수 있을 뿐만 아니라 사용자 crontab; d like it 's in' /etc/cron.d whatever& # 39, / etc / crontab '및'. 또한 특정 명령의세 부품 실행하십시오 운영하는 '에서' 반갑다 '볼 수 / etc / crontab'.
이러한 여러 곳에서 볼 수 있어요, 전체 일정을 다음 목록과 병합해야 서버에서부터 " events.".
I was about to write 등 스스로 스크립트입니다 신앙이니라 someone& # 39 에 이미 문제가 된 지 오래다.
하지만 실행하십시오 루트로 할 수 있습니다.
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
반복됨을 열거합니다 아웃해야 통해 각 사용자 이름과 그들의 crontab. # 39 는 crontab 소유하는지 won& 볼 수 있도록 해당 사용자가 다른 user&, s, t w / o 기술입니까 # 39 crontab 그들을 또는 루트.
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done
내가 됐지 먹어서나 스크랩트 (I& # 39, m trying to teach 내 자신을 더 훌륭한 포인트 (bash 스크립팅하는 도왔으매 that& # 39, s, t # 39 펄 여기 왜 don& 같은 항목을 참조). # 39 의 간단한 일을 하지 않지만, 대부분의 it& 당근이지를 뭐한테 데릭쉐퍼드와. # 39 의 제안에 대해 개별 users& # 39 찾는 Kyle& 사용한다. 뿐만 아니라, / etc / crontab crontab 다루는 '' 등의 스크립트에만 의해 시작된 '부품 실행하십시오' 에서 ',' '/etc/cron.hourly /etc/cron.daily' 등) 과 '작업' 에 /etc/cron.d 디렉터리입니다. 이러한 모든 및 디스플레이 뭔가 걸리는 병합합니다 다음과 같습니다.
mi h d m w user command
09,39 * * * * root [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -r -0 rm
47 */8 * * * root rsync -axE --delete --ignore-errors / /mirror/ >/dev/null
17 1 * * * root /etc/cron.daily/apt
17 1 * * * root /etc/cron.daily/aptitude
17 1 * * * root /etc/cron.daily/find
17 1 * * * root /etc/cron.daily/logrotate
17 1 * * * root /etc/cron.daily/man-db
17 1 * * * root /etc/cron.daily/ntp
17 1 * * * root /etc/cron.daily/standard
17 1 * * * root /etc/cron.daily/sysklogd
27 2 * * 7 root /etc/cron.weekly/man-db
27 2 * * 7 root /etc/cron.weekly/sysklogd
13 3 * * * archiver /usr/local/bin/offsite-backup 2>&1
32 3 1 * * root /etc/cron.monthly/standard
36 4 * * * yukon /home/yukon/bin/do-daily-stuff
5 5 * * * archiver /usr/local/bin/update-logs >/dev/null
단, 사용자, 그리고 내가 더 또는 덜 신규인지 시와 분을 통해 보여주는 것이라고 볼 수 있도록 매일 일정.
그동안 I& unbuntu, 데비안, Red Hat, ve 테스트되었습니다 # 39 에서 이 있다.
<! - 언어: 쉬 >.
#!/bin/bash
# System-wide crontab file and cron job directory. Change these for your system.
CRONTAB='/etc/crontab'
CRONDIR='/etc/cron.d'
# Single tab character. Annoyingly necessary.
tab=$(echo -en "\t")
# Given a stream of crontab lines, exclude non-cron job lines, replace
# whitespace characters with a single space, and remove any spaces from the
# beginning of each line.
function clean_cron_lines() {
while read line ; do
echo "${line}" |
egrep --invert-match '^($|\s*#|\s*[[:alnum:]_]+=)' |
sed --regexp-extended "s/\s+/ /g" |
sed --regexp-extended "s/^ //"
done;
}
# Given a stream of cleaned crontab lines, echo any that don't include the
# run-parts command, and for those that do, show each job file in the run-parts
# directory as if it were scheduled explicitly.
function lookup_run_parts() {
while read line ; do
match=$(echo "${line}" | egrep -o 'run-parts (-{1,2}\S+ )*\S+')
if [[ -z "${match}" ]] ; then
echo "${line}"
else
cron_fields=$(echo "${line}" | cut -f1-6 -d' ')
cron_job_dir=$(echo "${match}" | awk '{print $NF}')
if [[ -d "${cron_job_dir}" ]] ; then
for cron_job_file in "${cron_job_dir}"/* ; do # */ <not a comment>
[[ -f "${cron_job_file}" ]] && echo "${cron_fields} ${cron_job_file}"
done
fi
fi
done;
}
# Temporary file for crontab lines.
temp=$(mktemp) || exit 1
# Add all of the jobs from the system-wide crontab file.
cat "${CRONTAB}" | clean_cron_lines | lookup_run_parts >"${temp}"
# Add all of the jobs from the system-wide cron directory.
cat "${CRONDIR}"/* | clean_cron_lines >>"${temp}" # */ <not a comment>
# Add each user's crontab (if it exists). Insert the user's name between the
# five time fields and the command.
while read user ; do
crontab -l -u "${user}" 2>/dev/null |
clean_cron_lines |
sed --regexp-extended "s/^((\S+ +){5})(.+)$/\1${user} \3/" >>"${temp}"
done < <(cut --fields=1 --delimiter=: /etc/passwd)
# Output the collected crontab lines. Replace the single spaces between the
# fields with tab characters, sort the lines by hour and minute, insert the
# header line, and format the results as a table.
cat "${temp}" |
sed --regexp-extended "s/^(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(.*)$/\1\t\2\t\3\t\4\t\5\t\6\t\7/" |
sort --numeric-sort --field-separator="${tab}" --key=2,1 |
sed "1i\mi\th\td\tm\tw\tuser\tcommand" |
column -s"${tab}" -t
rm --force "${temp}"
getent passwd | cut -d: -f1 | perl -e'while(<>){chomp;$l = `crontab -u $_ -l 2>/dev/null`;print "$_\n$l\n" if $l}'
이렇게 되면 메싱, 사용자가 직접 사용하는 passwd 항목 및 cron 생략할지 없는 백성을 위한 것이 아니라 그들에게 이 sername 를출력합니다 그들의 crontab.
그래서 내가 여기서 찾을 수 있지만 이 경우는 대부분 드롭하기 나중에 다시 필요로 검색할 수 있습니다.
I like the simple 한 줄 광고문 오토메이티드 위쪽: >. 사용자를 위한 $ (잘라냅니다 - f1 - d: /etc/passwd); 책임질래 crontab - u $ user 뻦. 수행되
그러나 solris 갖지 않는 않습니다 - u 플래깅 인쇄인쇄 사용자 it& # 39 의 확인, 마치 수정할 수 있습니다.
for user in $(cut -f1 -d: /etc/passwd); do echo User:$user; crontab -l $user 2>&1 | grep -v crontab; done
사용자 목록을 얻을 수 있습니다 두고 던진 계정이 때 사용할 수 없습니다 오류 없이 crontab cron 상술합니다. / Etc / passwd 너무 존재할 수 있는 점을 유념하십시오 solris, 역할 (http://otl. /etc/user_attr).
다음 스트립 빼냅니다 의견 없이 빈 라인, 사용자들의 오류뿐만 crontab. # 39, re 는 모든 사용자 및 일자리를 목록니다 선택해제합니다 you& 함께 떠났다.
Sudo '를 사용하는 기록하십시오' 2 선. # 39 you& 경우 이미 루트, 제거, re iqn.
for USER in $(cut -f1 -d: /etc/passwd); do \
USERTAB="$(sudo crontab -u "$USER" -l 2>&1)"; \
FILTERED="$(echo "$USERTAB"| grep -vE '^#|^$|no crontab for|cannot use this program')"; \
if ! test -z "$FILTERED"; then \
echo "# ------ $(tput bold)$USER$(tput sgr0) ------"; \
echo "$FILTERED"; \
echo ""; \
fi; \
done
예 출력:
# ------ root ------
0 */6 * * * /usr/local/bin/disk-space-notify.sh
45 3 * * * /opt/mysql-backups/mysql-backups.sh
5 7 * * * /usr/local/bin/certbot-auto renew --quiet --no-self-upgrade
# ------ sammy ------
55 * * * * wget -O - -q -t 1 https://www.example.com/cron.php > /dev/null
내가 이 기능을 사용할 unbuntu (12 thru 16) 과 Red Hat (5 단계부터 7).
Cron 버전에 따라 달라집니다. Cron 비시 사용하는 FreeBSD, 내가 할 수 있는 이 같은 일이.
(cd /var/cron/tabs && grep -vH ^# *)
i want it, 탭 구분된 경우 더 있을지도 모르지만 뭔가 다음과 같습니다.
(cd /var/cron/tabs && grep -vH ^# * | sed "s/:/ /")
S # 39, sed 교체품을 that& ipv6-literal. 탭에 있는 부분.
이를 통해 더 많은 시스템 독립적인 반복할 수 있는 사용자의 / etc / passwd '와' 사용자 '각' 실행하십시오 crontab - l - u $ 저들이요
이 때 매우 유용한 스크립트입니다 주셔서 감사합니다. 난 이미 그것을 운영하는 작은 문제가 있는 일부 기존 시스템 (Red Hat Enterprise 3 처리할 수 있는 그레프 과 다르게 탭들 문자열), 그리고 다른 시스템과 아무런 성과를 /etc/cron.d/ (스크립트입니다 끝난 후 오류로). 여기서는 작업하십시오 패치 등 할 수 있었다.
2a3,4
> #See: http://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users
>
27c29,30
< match=$(echo "${line}" | egrep -o 'run-parts (-{1,2}\S+ )*\S+')
---
> #match=$(echo "${line}" | egrep -o 'run-parts (-{1,2}\S+ )*\S+')
> match=$(echo "${line}" | egrep -o 'run-parts.*')
51c54,57
< cat "${CRONDIR}"/* | clean_cron_lines >>"${temp}" # */ <not a comment>
---
> sys_cron_num=$(ls /etc/cron.d | wc -l | awk '{print $1}')
> if [ "$sys_cron_num" != 0 ]; then
> cat "${CRONDIR}"/* | clean_cron_lines >>"${temp}" # */ <not a comment>
> fi
67c73
< sed "1i\mi\th\td\tm\tw\tuser\tcommand" |
---
> sed "1i\mi${tab}h${tab}d${tab}m${tab}w${tab}user${tab}command" |
덕분에 함께 사과 및 유코 두데.
이것은 버전 10 - 이제.
나는 이제 게시하기를 스크립트입니다 전체 삽입하십시오.
https://gist.github.com/myshkin-uk/d667116d3e2d689f23f18f6cd3c71107
루프을 문제가 있기 때문에 통해 파일 ('/ etc / passwd') 와 작업 수행, 나는 누각되었습니다 대한 적절한 외곽진입 어떻게 파일을 읽을 (데이터 스트림을 변수) 한 줄씩 (및/또는 필드 단위)?:
while IFS=":" read -r user _
do
echo "crontab for user ${user}:"
crontab -u "$user" -l
done < /etc/passwd
/ Etc / passwd '이' 로 ':' 사용하여 판독합니다 행별로 필드 구분. 말해 '읽기', '$ 누르고 첫 번째 필드는 boot-r 사용자 을 사용자' 와 '' 우리가 만드는 미삭 (이것이 단순한 정크 가변으로 무시하려면 필드).
그런 다음, 이 방법을 사용하여 사용자 ',' u '변수' $ 호출하십시오 crontab - which we 쿼트에 안전을 위해 (와일드링이 it 공백이? 이런 것 같지는 않다고 확장하지만 파일에 대해서는 전혀 알 수 없다).