Create a bash shell script that would manage this log: ************ [/var/log/me
ID: 3806262 • Letter: C
Question
Create a bash shell script that would manage this log:
************ [/var/log/message: General message and system related stuff ] ************
Jul 17 22:04:25 router dnsprobe[276]: dns query failed
Jul 17 22:04:29 router last message repeated 2 times
Jul 17 22:04:29 router dnsprobe[276]: Primary DNS server Is Down... Switching To Secondary DNS server
Jul 17 22:05:08 router dnsprobe[276]: Switching Back To Primary DNS server
Jul 17 22:26:11 debian -- MARK --
Jul 17 22:46:11 debian -- MARK --
Jul 17 22:47:36 router -- MARK --
Jul 17 22:47:36 router dnsprobe[276]: dns query failed
Jul 17 22:47:38 debian kernel: rtc: lost some interrupts at 1024Hz.
Jun 17 22:47:39 debian kernel: IN=eth0 OUT= MAC=00:0f:ea:91:04:07:00:08:5c:00:00:01:08:00 SRC=61.4.218.24 DST=192.168.1.100 LEN=60 TOS=0x00 PREC=0x00 TTL=46 ID=21599 DF PROTO=TCP SPT=59297 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0
Explanation / Answer
(Steps to create bash shell script to get var/log/messages directory.However my testing environment is ubuntu and hence it was var/log/syslog)
each Linux script using bash will start with the following line:
#!/bin/bash
1. Open the text editor
To open gedit text editior using the terminal, press CTRL + ALT + T on your keyboard and type gedit. Now you can edit in text editor
2. Type the following script lines in the editor
#!/bin/bash
dmesh
3. save the file with .sh extension, simply I've saved it as demo.sh.
4. To make the file executable, which is not default mode.
Go to terminal and type the following command
chmod +x demo.sh
Now demo.sh will be an executable one.
5.) To test the script, type the following in the terminal
./demo.sh