16.04: Como faço o cron criar o cron.log e monitorá-lo em tempo real?

3

Eu sei que os eventos cron são armazenados em /var/log/syslog e posso usar um comando como:

sudo cat /var/log/syslog | grep cron 

para vê-los.

Preferiria que o sistema mantivesse um arquivo de log do cron separado para que ele não trabalhasse tanto assistindo, já que ele classifica todas as mensagens syslog para extrair as notificações cron .

Então eu quero usar o comando watch , então eu sempre tenho uma janela de terminal aberta mostrando a atividade do cron.

Como eu faço o sistema manter um arquivo /var/log/cron.log separado?

    
por SDsolar 19.10.2017 / 03:18

2 respostas

7

Aqui está a maneira mais simples de fazer isso:

- > Faça uma alteração em /etc/rsyslog.d/50-default.conf com seu editor favorito:

sudo gedit /etc/rsyslog.d/50-default.conf

Use Ctrl - f (find) e digite cron para encontrar a linha que diz

#cron.*         /var/log/cron.log

Remova o # dessa linha. Em seguida, reinicie o serviço:

service rsyslog restart

A partir daí, todas as saídas relacionadas ao cron irão para /var/log/cron.log

Para impedir que cron envie e-mails de resumo, coloque esta linha no início do seu arquivo crontab :

crontab -e
(Insert first line)
MAILTO=""

Em seguida, para assisti-lo quase em tempo real, primeiro crie um comando wcron :

echo "#!/bin/bash" >wcron
echo "watch -n 10 tail -n 25 /var/log/cron.log" >>wcron
chmod +x wcron
sudo cp wcron /usr/sbin
  • watch -n 10 diz para atualizar a página a cada 10 segundos
  • tail -n 25 diz para exibir as últimas 25 entradas

Sempre que você quiser monitorar cron em tempo quase real em uma janela de terminal, digite:

wcron

Isso é útil para abrir em um dos quatro desktops virtuais, talvez junto com o System Monitor.

Se você quiser ver mais do que apenas os tempos de inicialização de tarefas mais longas, é fácil fazer com que o cron.log exiba os horários de início e os horários de encerramento do script, além de mensagens de status de saída diferentes de zero. / strong>

Como alterar o nível de log do cron?

EXTRATO PARAPHRASED:

% bl0ck_qu0te%

Para adicionar a opção -L 15 , abra o editor usando:

sudo systemctl edit --full cron

OU RECOMENDO:

sudo gedit /lib/systemd/system/cron.service

e substitua a linha

ExecStart=/usr/sbin/cron -f $EXTRA_OPTS

com

ExecStart=/usr/sbin/cron -L 15 -f $EXTRA_OPTS

Em seguida, recarregue a configuração:

sudo systemctl restart cron

Ele também será carregado na inicialização.

Isso permite que wcron mostre todas as informações que você precisa para assistir ao seu sistema cron enquanto ele executa seus scripts no horário.

Uma ideia final para monitorar cron é ensinar seus scripts a falar.

16.04 LTS Como fazer o sistema anunciar o horário no topo da hora com o eSpeak

Eu tenho muitos dos meus scripts anunciados quando eles começam e quando eles param, ou se encontram erros.

O volume pode ser ajustado no comando espeak para que eles sejam sutis.

    
por SDsolar 19.10.2017 / 03:18
1

Todas as manhãs, cron envia-me um backup diário em um único anexo de arquivo .tar . No momento do envio, ele me envia um e-mail separado com detalhes que NÃO aparecem em /var/log/syslog . Isso pode ser de interesse para você:

Anacron job 'cron.daily' on dell 
Anacron <[email protected]>
4:05 AM (15 hours ago)

to root, bcc: me 
/etc/cron.daily/daily-backup:
bin/
bin/.websync.new
bin/log-gsu-del
bin/now
bin/lid
bin/usb-suspend
bin/edmonton
bin/toggle-touchpad
bin/edmonton.2
bin/dbus-screen-lock
bin/test
bin/log-gsu-testfile
bin/one-cpu-pids
bin/dkms-gui
bin/test-parms
bin/log-gsu-zenity-test
bin/log-boot
bin/adpative-brightness-configuration-file
bin/strip-first-rec
bin/log-gsu-nautilus
bin/.websync.ver2
bin/sed-limit-file
bin/new2
bin/backup
bin/websyncExpandListArr2
bin/seconds
bin/adaptive-brightness-configuration-file
bin/sudotest
bin/testver
bin/zenity-test
bin/log-cron
bin/adaptive-brightness-config
bin/gtk-icons
bin/secSunset
bin/deltest2
bin/snakes
bin/.websync.new2
bin/indicator-sysmonitor-display
bin/strip-first-rec2
bin/894470
bin/rm2
bin/bafman
bin/NIGHTMARE
bin/gsu
bin/log-gsu-geit
bin/lock-screen-timer
bin/grab-website-images
bin/websync
bin/hotplugtv
bin/websyncExpandListArr
bin/log-hotplugtv
bin/ProgressBar
bin/summary-log
bin/cpu-top-summary
bin/yad_notification
bin/log-file
bin/log-gsu-gedit
bin/dbus-unlock-screen
bin/log-gsu-log-file
bin/log-gsu-50_r8169-ethernet
bin/deltest3
bin/start-conky
bin/testwget
bin/r8169
bin/stat.c_diff
bin/text-spinner
bin/.websync.sav
bin/log-gsu-daily-backup
bin/stat.c
bin/.websync
bin/cron-minute-test
bin/edmonton.1
bin/ListArr
tar: Removing leading '/' from member names
/usr/local/bin/
/usr/local/bin/iwlwifi-reset
/usr/local/bin/windows
/usr/local/bin/.auto-brightness-config
/usr/local/bin/zenity
/usr/local/bin/spawn-progress-multi
/usr/local/bin/full-backup
/usr/local/bin/top-of-hour-chime
/usr/local/bin/sun-hours
/usr/local/bin/kill-previous-version
/usr/local/bin/rm-kernels-debug
/usr/local/bin/sunrise
/usr/local/bin/bell/
/usr/local/bin/bell/sounds/
/usr/local/bin/bell/sounds/Slick.ogg
/usr/local/bin/bell/sounds/Blip.ogg
/usr/local/bin/bell/sounds/Positive.ogg
/usr/local/bin/bell/sounds/Amsterdam.ogg
/usr/local/bin/bell/sounds/message.ogg
/usr/local/bin/bell/sounds/bell.ogg
/usr/local/bin/bell/sounds/Mallet.ogg
/usr/local/bin/bell/sounds/Rhodes.ogg
/usr/local/bin/bell/sounds/default.ogg
/usr/local/bin/bell/bell-select-menu
/usr/local/bin/playall-bells
/usr/local/bin/testfile.touch
/usr/local/bin/cron-reboot-cycle-grub-background
/usr/local/bin/zaprestore
/usr/local/bin/zap/
/usr/local/bin/zap/hello.o
/usr/local/bin/zap/Assembly-Intro-hello/
/usr/local/bin/zap/Assembly-Intro-hello/FreeBSD/
/usr/local/bin/zap/Assembly-Intro-hello/FreeBSD/hello
/usr/local/bin/zap/Assembly-Intro-hello/FreeBSD/hello.asm
/usr/local/bin/zap/Assembly-Intro-hello/BeOS/
/usr/local/bin/zap/Assembly-Intro-hello/BeOS/hello
/usr/local/bin/zap/Assembly-Intro-hello/BeOS/hello.asm
/usr/local/bin/zap/Assembly-Intro-hello/Linux/
/usr/local/bin/zap/Assembly-Intro-hello/Linux/hello
/usr/local/bin/zap/Assembly-Intro-hello/Linux/hello.asm
/usr/local/bin/zap/hello.asm
/usr/local/bin/zapboot
/usr/local/bin/rm-kernels
/usr/local/bin/doug-rm-kernels-server
/usr/local/bin/echo
/usr/local/bin/startup-scripts/
/usr/local/bin/testver
/usr/local/bin/spawn-progress-log
/usr/local/bin/sunset
/usr/local/bin/change-attributes
/usr/local/bin/rm-kernels-server
/usr/local/bin/bottom-of-hour-chime
/usr/local/bin/rm2
/usr/local/bin/spawn-progress-bar
/usr/local/bin/Link to auto-brightness-config
/usr/local/bin/auto-brightness-config
/usr/local/bin/892077
/usr/local/bin/set-hyper-threading
/usr/local/bin/bell-menu
/usr/local/bin/display-auto-brightness
/usr/local/bin/dd
/usr/local/bin/load-default-bell
tar: Removing leading '/' from member names
/etc/cron.d/
/etc/cron.d/turn-off-hyper-threading
/etc/cron.d/anacron
/etc/cron.d/test-reboot
/etc/cron.d/php
/etc/cron.d/.placeholder
/etc/cron.d/test-directory/
/etc/cron.d/display-auto-brightness
/etc/cron.d/touch-vmlinuz
/etc/cron.d/popularity-contest
/etc/cron.d/cycle-grub-background
/etc/cron.daily/
/etc/cron.daily/bsdmainutils
/etc/cron.daily/sun-hours
/etc/cron.daily/google-earth
/etc/cron.daily/dpkg
/etc/cron.daily/update-notifier-common
/etc/cron.daily/0anacron
/etc/cron.daily/daily-backup
/etc/cron.daily/apt-compat
/etc/cron.daily/google-chrome
/etc/cron.daily/man-db
/etc/cron.daily/logrotate
/etc/cron.daily/passwd
/etc/cron.daily/apport
/etc/cron.daily/.placeholder
/etc/cron.daily/upstart
/etc/cron.daily/mlocate
/etc/cron.daily/popularity-contest
/etc/cron.daily/cracklib-runtime
/etc/cron.hourly/
/etc/cron.hourly/.placeholder
/etc/cron.monthly/
/etc/cron.monthly/0anacron
/etc/cron.monthly/.placeholder
/etc/crontab
/etc/cron.weekly/
/etc/cron.weekly/apt-xapian-index
/etc/cron.weekly/update-notifier-common
/etc/cron.weekly/0anacron
/etc/cron.weekly/man-db
/etc/cron.weekly/.placeholder
/etc/cron.weekly/fstrim
tar: Removing leading '/' from member names
/etc/systemd/
/etc/systemd/system/
/etc/systemd/system/graphical.target.wants/
/etc/systemd/system/graphical.target.wants/accounts-daemon.service
/etc/systemd/system/dbus-org.freedesktop.ModemManager1.service
/etc/systemd/system/sysinit.target.wants/
/etc/systemd/system/sysinit.target.wants/brltty.service
/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
/etc/systemd/system/sysinit.target.wants/resolvconf.service
/etc/systemd/system/sysinit.target.wants/friendly-recovery.service
/etc/systemd/system/bluetooth.target.wants/
/etc/systemd/system/bluetooth.target.wants/bluetooth.service
/etc/systemd/system/dbus-org.freedesktop.thermald.service
/etc/systemd/system/printer.target.wants/
/etc/systemd/system/printer.target.wants/cups.service
/etc/systemd/system/multi-user.target.wants/
/etc/systemd/system/multi-user.target.wants/unattended-upgrades.service
/etc/systemd/system/multi-user.target.wants/cron.service
/etc/systemd/system/multi-user.target.wants/tlp.service
/etc/systemd/system/multi-user.target.wants/dns-clean.service
/etc/systemd/system/multi-user.target.wants/ufw.service
/etc/systemd/system/multi-user.target.wants/rsyslog.service
/etc/systemd/system/multi-user.target.wants/cgproxy.service
/etc/systemd/system/multi-user.target.wants/snapd.firstboot.service
/etc/systemd/system/multi-user.target.wants/cups.path
/etc/systemd/system/multi-user.target.wants/pppd-dns.service
/etc/systemd/system/multi-user.target.wants/snapd.service
/etc/systemd/system/multi-user.target.wants/smartd.service
/etc/systemd/system/multi-user.target.wants/whoopsie.service
/etc/systemd/system/multi-user.target.wants/anacron.service
/etc/systemd/system/multi-user.target.wants/cgmanager.service
/etc/systemd/system/multi-user.target.wants/atd.service
/etc/systemd/system/multi-user.target.wants/lm-sensors.service
/etc/systemd/system/multi-user.target.wants/cups-browsed.service
/etc/systemd/system/multi-user.target.wants/remote-fs.target
/etc/systemd/system/multi-user.target.wants/ModemManager.service
/etc/systemd/system/multi-user.target.wants/NetworkManager.service
/etc/systemd/system/multi-user.target.wants/thermald.service
/etc/systemd/system/multi-user.target.wants/avahi-daemon.service
/etc/systemd/system/multi-user.target.wants/snapd.autoimport.service
/etc/systemd/system/multi-user.target.wants/snapd.core-fixup.service
/etc/systemd/system/multi-user.target.wants/snapd.boot-ok.service
/etc/systemd/system/multi-user.target.wants/binfmt-support.service
/etc/systemd/system/multi-user.target.wants/networking.service
/etc/systemd/system/multi-user.target.wants/vnstat.service
/etc/systemd/system/dbus-org.freedesktop.Avahi.service
/etc/systemd/system/display-manager.service.wants/
/etc/systemd/system/display-manager.service.wants/gpu-manager.service
/etc/systemd/system/timers.target.wants/
/etc/systemd/system/timers.target.wants/apt-daily.timer
/etc/systemd/system/timers.target.wants/snap-repair.timer
/etc/systemd/system/timers.target.wants/snapd.refresh.timer
/etc/systemd/system/timers.target.wants/apt-daily-upgrade.timer
/etc/systemd/system/getty.target.wants/
/etc/systemd/system/getty.target.wants/[email protected]
/etc/systemd/system/syslog.service
/etc/systemd/system/sockets.target.wants/
/etc/systemd/system/sockets.target.wants/avahi-daemon.socket
/etc/systemd/system/sockets.target.wants/uuidd.socket
/etc/systemd/system/sockets.target.wants/snapd.socket
/etc/systemd/system/sockets.target.wants/cups.socket
/etc/systemd/system/sockets.target.wants/acpid.socket
/etc/systemd/system/sockets.target.wants/apport-forward.socket
/etc/systemd/system/default.target.wants/
/etc/systemd/system/default.target.wants/ureadahead.service
/etc/systemd/system/display-manager.service
/etc/systemd/system/hibernate.target.wants/
/etc/systemd/system/hibernate.target.wants/anacron-resume.service
/etc/systemd/system/dbus-org.bluez.service
/etc/systemd/system/network-online.target.wants/
/etc/systemd/system/network-online.target.wants/networking.service
/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service
/etc/systemd/system/final.target.wants/
/etc/systemd/system/final.target.wants/snapd.system-shutdown.service
/etc/systemd/system/sleep.target.wants/
/etc/systemd/system/sleep.target.wants/tlp-sleep.service
/etc/systemd/system/paths.target.wants/
/etc/systemd/system/paths.target.wants/acpid.path
/etc/systemd/system/suspend.target.wants/
/etc/systemd/system/suspend.target.wants/anacron-resume.service
/etc/systemd/system/hybrid-sleep.target.wants/
/etc/systemd/system/hybrid-sleep.target.wants/anacron-resume.service
/etc/systemd/user/
/etc/systemd/resolved.conf
/etc/systemd/network/
/etc/systemd/sleep.conf
/etc/systemd/system.conf
/etc/systemd/bootchart.conf
/etc/systemd/logind.conf
/etc/systemd/journald.conf
/etc/systemd/user.conf
/etc/systemd/timesyncd.conf
tar: Removing leading '/' from member names
/lib/systemd/system-sleep/
/lib/systemd/system-sleep/iwlwifi-reset
/lib/systemd/system-sleep/r8169-reset
/lib/systemd/system-sleep/wpasupplicant
/lib/systemd/system-sleep/sound
/lib/systemd/system-sleep/hdparm
/lib/systemd/system-sleep/display-auto-brightness
tar: Removing leading '/' from member names
/etc/rc.local
tar: Removing leading '/' from member names
/etc/default/grub
Desktop/
Desktop/Link to websync
Desktop/Link to MyEmployer Expense Report.xlsx
Desktop/Link to bafman
Desktop/Lock Screen Timer
Desktop/Link to To-Do List.odt
Desktop/IG.ods
Desktop/Link to auto-brightness-config
Desktop/KillDuplicate
Desktop/Conky
Desktop/Link to Payroll Hours.ods
Documents/34 Shaunessy repairs.odt
Documents/Edmotnon TV Channels.ods
Documents/Fan Control.odt
Documents/intel_cstate.idle_max=1.odt
Documents/Little Mermaid Pez.odt
Documents/Music File Diff.odt
Documents/Sorry I missed Thanksgiving Dinner.odt
Documents/Stanley Cup 2017.odt
Documents/To-Do List.odt
.asunder
.asunder_album_artist
.asunder_album_genre
.asunder_album_title
.BafmanDirs
.bafmanDirs
.bafmanDirs~
.BafmanDirs.sav
.bafmanDirs.sav
.bafmanDirs.sav2
.bafmanDirs.sav3
.bafmanDirs.sav4
.bafmanFiles
.bafmanFiles~
.bafmanFiles.sav
.bafmanFiles.sav2
.bafmanFiles.sav3
.bafmanFiles.sav4
.bafmanLog
.bafmanNdx
.bafmanSort
.bash_history
.bash_logout
.bashrc
.conkyrc
.conkyrc~
.dmrc
.dpkg.list
.gksu.lock
.ICEauthority
.ilg-config
.indicator-sysmonitor.json
.last-text-spinner
.lesshst
.mbr.sav
.mtab.fuseiso
.nvidia-settings-rc
.packages
.profile
.selected_editor
.sudo_as_admin_successful
.Wammu
.websync
.websync~
.websync.bad.sort
.websyncNdx
.websync.sav
.websyncSort
.wget-hsts
.Xauthority
.xinputrc
.xscreensaver
.xsession-errors
.xsession-errors.old

Você pode pesquisar em AU sobre como configurar cron email. Se estiver interessado, posso descobrir o Q & amp; A aqui em AU para saber como configurar o backup diário usando cron .

    
por WinEunuuchs2Unix 19.10.2017 / 03:36