Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Shell script newbie- how to generate service log from shell script Post 303031655 by bakunin on Sunday 3rd of March 2019 06:25:33 PM
Old 03-03-2019
First off: i apologise for dragging this out a bit. Once you are experienced you could probably do all the reasoning we are going through here in a few seconds of thought. But since you lack this experience and i want to show you how you tackle this sort of problems i show you and discuss every point applicable to any monitoring script. Some of what i will tell you will not be applicable to NTP because it is a very simply service. Others are more complicated and you will need this kind of reasoning, though.

So, bear with me - you might have come asking for a meal, i show you how to cook yourself.

Quote:
Originally Posted by xiaogeji
the following is my plan and let me know if anything doesnt make sense Smilie
All makes sense to me, save for one point:

Quote:
Originally Posted by xiaogeji
But if I am really stuck,as long as the "$(success status),$(service name),$(activity)" are in the output then it will still be fine
Quote:
Originally Posted by xiaogeji
I shouldve clarified earlier that the only service I need to work on is ntpd.
Compare these two quotes. If there is only one service you want to monitor then why repeat the name of that service in every line? Do you really need that? Because the file will already be named "ntpd.log" or something such, so one would know that the messsages in there are about NTP or ntpd respectively, no?

Now, having identified the fields (that is: the type of information you want to log) you need to identify how this information will be comprised in detail. What do i mean by that?

Well, take "success status", for instance: Th simplest model would be to have to possible values: "success" or "failure" (or "error" or whatever you want to name it). You could also have three possible outcomes, "success", "warning" and "failure". You could even have more. Have a look at the documentation of syslog to get ideas. Basically syslog has "severity levels" which map to what i called "success status" here, seven of them. You specify a "threshhold severity" and everything "above" that severity will be logged, everything else will not.

Quote:
Originally Posted by xiaogeji
the date is optional depending on the complexity:
Really? If you leave out the time stamp you have a message and don't know when that was. It is easy to do that but i wonder if it makes sense to do it this way.

OK, go over your list a seond time, plan on how many success status you want to have (and how they are called) and how you want to define them: What constitutes "success", what constitutes a "failure"? And how much has to go "quite not right" when you label the outcome a "warning". Once you do this we finally get around to writing the script.

I hope this helps.


bakunin

Last edited by bakunin; 03-04-2019 at 03:27 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

generate xml from a shell script

Hello! I would like to generate an xml file from the output of various commands generated from within a shell script (some will be in CDATA). At the moment the only solution I have come up with is echoing xml tags around the commands eg. echo "<bitism>" >> outputfile /usr/sbin/prtconf... (1 Reply)
Discussion started by: speedieB
1 Replies

2. Shell Programming and Scripting

Help - shell script newbie

My problem looks like it should have a simple solution but it seems that after many days of research I cannot find a good solution. What I have is an input file that contains lines of information. What I need is to extract specific information from that file. What I know is that somewhere in the... (2 Replies)
Discussion started by: eback
2 Replies

3. Shell Programming and Scripting

how do i generate random integer using only shell script

Hi All, I need to generate 4 digit random no using only shell script. Please help in this ASAP. Thanks in advance... Regards, sridhar. (1 Reply)
Discussion started by: sridhusha
1 Replies

4. Shell Programming and Scripting

Shell Script Help -I'm a newbie

Can someone help me write this shell script? I am completely new to shell and as a fun task my uncle has challenged me a problem (out of all other people). Basically, all he wants me to do is to create backup file in a folder that is named “disables.” This is what he said: create a shell script... (0 Replies)
Discussion started by: hotcutiepie05
0 Replies

5. Infrastructure Monitoring

Shell Script - Generate SNMP Traps

Good morning to you all I´m kinda of a noob to scripting, and my knowledge is still very basic: anyway, I´ve developed a small .sh script with the following purpose: - it will check a result file, checking if it has any values, or if it´s empty - if it´s empty it will send an email What... (0 Replies)
Discussion started by: zarahel
0 Replies

6. Shell Programming and Scripting

Shell Script for a newbie

Hello all, I want to write a shell script to list the contents of a directory and number them and write them to a file. For example, if I have a directory temp and the contents of the directory are alpha, beta and gamma. I want to write these filenames to a file "test" in a numbered manner. ... (7 Replies)
Discussion started by: grajp002
7 Replies

7. Shell Programming and Scripting

generate logfile in a shell script

Unix Gurus, I have a shell script which has few "echo" statements. I am trying to create a logfile where all the outputs of the echo statement sare stored. I will have to add this as the final step in the existing script so that everytime the script runs, a logfile is generated with all the... (1 Reply)
Discussion started by: shankar1dada
1 Replies

8. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

9. Shell Programming and Scripting

Shell script to compare and generate a new file

Requirement is I have two files their format is File1 - input_file ----- tmp_value|3|number|| tmp_value1|3|alpha|| tmp_value2|6|alpha|AA AA| tmp_value3|15|number|000000005| tmp_value4|15|number|000000000000000| tmp_value5|11|alpha|bbbbbbbbbbb| tmp_value6|11|alpha|bb bb| input_file ... (4 Replies)
Discussion started by: greenworld123
4 Replies

10. Shell Programming and Scripting

Generate documentation for a shell script

Hi, I've written a shell script with proper intentation and commenting structure. However, I would like to generate documentation for the shell which I have written. Is there any tool as such to generate it like we have javagen/docgen ? Please help. Thanks, Arjun (0 Replies)
Discussion started by: arjun_arippa
0 Replies
All times are GMT -4. The time now is 06:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy