Sponsored Content
Full Discussion: Script to check logs
Top Forums Shell Programming and Scripting Script to check logs Post 302707769 by nextyoyoma on Sunday 30th of September 2012 12:28:04 AM
Old 09-30-2012
You need to quote "$SearchString1" to prevent word splitting when the variable is expanded. Think of it this way: if you typed in "grep Sep 29" it would think you were trying to look for the string "Sep" in the file "29." So when the shell expands $SearchString1, it is as if you had typed in "grep Sep 29" without any quotes. By quoting, you prevent the shell from splitting the argument into two words.

EDIT: There are a number of other problems, or at least inefficiencies in your script, but as a novice scripter myself, I understand that sometimes you just struggle through it to get the job done. Some things to consider:

1) Consider whitespace when writing scripts. Your script with meaningful whitespace:

Code:
#!/bin/ksh
# Start of main processing

echo "enter String One";
read SearchString1
echo "Enter String two";
read SearchString2
echo "$SearchString1"
for i in `cat ~/Desktop/Loginput`;
	do
		if [ "$SearchString2" == '' ]
			then
				cat $i|grep "$SearchString1" >>"Logoutput"
			else
				cat $i|grep "$SearchString1"|grep $SearchString2 >>"Logoutput"
		fi
	done
exit 0

I did move the "then" statement to its own line. While the whitespace means nothing to the shell, it makes it much easier for humans to read because you can see the organizational structure of your script.

2) ";" is not needed at the end of a line. The shell interprets a newline as the end of a command, unless it is quoted, in which case it is taken literally (example below):
Code:
echo "
"

3) It looks like you are testing whether the second search string is blank. An easier way to do this is simply [[ "$SearchString2" ]]. If the string is null, the test will return false, and the if command will execute the "else" portion of the construct.

Last edited by nextyoyoma; 09-30-2012 at 01:47 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

is it possible to check logs in UNIX who deleted the files?

Hello, is it possible to check logs in UNIX who deleted the files? Is there logs in UNIX besides .sh_history? (1 Reply)
Discussion started by: james_falco
1 Replies

2. Shell Programming and Scripting

How to check whether logs are updating or not?

how to check whether logs are updating or not in unix is there any built in command or function ? (1 Reply)
Discussion started by: mail2sant
1 Replies

3. Solaris

logs to check

Hi all i want to know what are the logs we need to check when the server is down and how to resolve to make server UP? please help me with this (8 Replies)
Discussion started by: vkav
8 Replies

4. Solaris

archive logs mount point space check script

I have the below shell script which is checking /archlog mount point space on cappire(solaris 10) server. When the space usage is above 80% it should e-mail. When i tested this script it is working as expected. -------------------------------------------------------------------------... (0 Replies)
Discussion started by: dreams5617
0 Replies

5. UNIX for Dummies Questions & Answers

Check for updation/error/stuck of logs

Hi All, I'm a newbie in Linux Programming.:) Got some 500 processes running and I have around 20-30 logs updating for every 2mins on a server. The logs which i'm referring usually contains book name,run ids(not PID's),process name etc etc. I'm interested in finding out whether some particular... (1 Reply)
Discussion started by: Nand Kishor
1 Replies

6. Shell Programming and Scripting

Need to check logs

I have nearly 25+ tail commands which we need to verify the logs if there is any errors on current or previous date with time. I need this to be automate and send email to me with details. Please help me on this. (5 Replies)
Discussion started by: Nasir HussainSM
5 Replies

7. Shell Programming and Scripting

Any utility or tool to check logs

HI, In our project daily we need to check for some errors in around 45-50 folders. Please let me know if there is any utility tool using which 1 can check each folder and file for error. Use: Monday we are checking if there were any error in files generated on Monday Tuesday to Wednesday we... (7 Replies)
Discussion started by: ankush_mehra
7 Replies

8. Shell Programming and Scripting

Script to check response time from nginx logs

Hi, My goal is to monitor the response time from the access logs of nginx server. I am using gawk to print the needed fields - 'response time' and 'name of the service' from nginx logs. Command: gawk '($6 ~ /cloudservice/) {print $10, $6}' access.log Output: 0.645 /nc/cloudservice... (6 Replies)
Discussion started by: nshah11
6 Replies

9. Shell Programming and Scripting

To check if a file is open and in use (logs are being written to it)

Hello Experts, I need to write a shell script to check if a file is open and something is being written to it. I want to know how OS handles it. I checked with lsof command but it is not working. For a test I did this. while true; do echo `date` >>abc.txt; done then I checked lsof |... (5 Replies)
Discussion started by: shekhar_4_u
5 Replies

10. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies
db_printlog(8)						      System Manager's Manual						    db_printlog(8)

NAME
db_printlog - Displays database log file (Enhanced Security) SYNOPSIS
/usr/tcb/bin/db_printlog [-h home] FLAGS
Specify a home directory for the database. The correct directory for enhanced security is /var/tcb/files. DESCRIPTION
A customized version of the Berkeley Database (Berkeley DB) is embedded in the operating system to provide high-performance database sup- port for critical security files. The DB includes full transactional support and database recovery, using write-ahead logging and check- pointing to record changes. The db_printlog utility provides a way to view the log file associated with the security database. RETURN VALUES
The db_printlog utility exits 0 on success, and >0 if an error occurs. ENVIRONMENT VARIABLES
If the -h option is not specified and the environment variable DB_HOME is set, it is used as the path of the database home. The home directory for security is /var/tcb/files. FILES
/var/tcb/files/auth.db /var/tcb/files/dblogs/* RELATED INFORMATION
Commands: db_checkpoint(8), db_recover(8), db_stat(8) delim off db_printlog(8)
All times are GMT -4. The time now is 05:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy