Usando o script bash para selecionar / visualizar apenas dados específicos do arquivo de log

2

Meu NAS cria um arquivo de log no formato abaixo:

<30>1 2014-07-21T05:02:10+02:00 ABC-NAS qlogd 6432 - - qlogd[6432]: event log: Users: Glacier, Source IP: 127.0.0.1, Computer name: localhost, Content: [Glacier] Backup job [Backup ABC-PC] finished successfully

<30>1 2014-07-21T05:02:27+02:00 ABC-NAS qlogd 6432 - - qlogd[6432]: event log: Users: Glacier, Source IP: 127.0.0.1, Computer name: localhost, Content: [Glacier] Backup job [Backup ABC-HTPC] finished successfully

<28>1 2014-07-21T05:10:59+02:00 ABC-NAS qlogd 6920 - - qlogd[6920]: event log: Users: Glacier, Source IP: 127.0.0.1, Computer name: localhost, Content: [Glacier] Backup job [Backup ABC-NAS] is abnormal shutdown

<30>1 2014-07-21T06:00:15+02:00 ABC-NAS qlogd 6920 - - qlogd[6920]: event log: Users: Glacier, Source IP: 127.0.0.1, Computer name: localhost, Content: [Glacier] Backup job [Backup ABC Metadata] started

<30>1 2014-07-21T06:00:27+02:00 ABC-NAS qlogd 6920 - - qlogd[6920]: event log: Users: Glacier, Source IP: 127.0.0.1, Computer name: localhost, Content: [Glacier] Backup job [Backup ABC Metadata] finished successfully

Usando um script BASH, gostaria de criar um arquivo de texto contendo apenas:

Monday 21 July 2014 - 04:10 AM
Glacier Backup job [Backup ABC-PC] finished successfully

Monday 21 July 2014 - 07:02 AM
Glacier Backup job [Backup ABC-HTPC] finished successfully

e assim por diante.

Eu tenho tentado com cat e grep, mas logo fica muito complicado para mim. Quem pode me ajudar na direção certa?

    
por JERO79 26.07.2014 / 17:07

1 resposta

0

aqui é um script bash de força bruta super simples

cat log | cut -d " " -f 2,20- | while read -r date message; do
  echo $date
  echo $message
done

exemplo de saída

2014-07-21T05:02:10+02:00
[Glacier] Backup job [Backup ABC-PC] finished successfully


2014-07-21T05:02:27+02:00
[Glacier] Backup job [Backup ABC-HTPC] finished successfully

Se você deseja mais recursos, então eu aconselho você a aprender python.

    
por 26.07.2014 / 17:33