Print if found non-desired result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print if found non-desired result
# 1  
Old 01-12-2015
Print if found non-desired result

I have a result like this

Code:
root@server [~]# grep -rl maldet /etc/cron*
/etc/cron.d/maldet_daily
/etc/cron.d/malcron
/etc/cron.d/malcrondaily
/etc/cron.d/malcronweekly

What I need is, I need an if/else condition such that, if there is any output other than /etc/cron.d/maldet_daily in the grep command, an "else" condition would say "critical: more than one maldet cron found: /etc/cron.d/malcron -- /etc/cron.d/malcrondaily -- /etc/cron.d/malcronweekly " If only /etc/cron.d/maldet_daily is there in output, it should be "OK:"
# 2  
Old 01-12-2015
Hello anil510,

Could you please try following and let me know if this helps.(Not tested though)
Code:
grep -rl maldet /etc/cron* | awk '{split($0, X, " ");}END{if(length($0)== 1){print "OK"} else {print "CRITICAL"}}'

Thanks,
R. Singh
# 3  
Old 01-12-2015
R singh, Sorry, Its not working
# 4  
Old 01-12-2015
Hello anil510,

Could you please try following and let me know if this helps.
Code:
cat check_cron.ksh
A=`grep -rl  maldet /etc/cron*`
echo $A | awk '{split($0, X, " ");}END{if(length(X)== 1){print "OK"} else if(length(X)==0){print "NO results found."} else {print "CRITICAL"}}'

This should work.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 01-12-2015
Almost fine it seems. But not the real result.
Code:
root@server [~]#  grep -rl  maldet /etc/cron*
/etc/cron.d/maldetweekly
/etc/cron.d/maldet_daily
/etc/cron.d/malcron
root@server [~]# A=`grep -rl  maldet /etc/cron*` ; echo $A | awk '{split($0, X, " ");}END{if(length(X)== 1){print "OK"} else if(length(X)==0){print "NO results found."} else {print X[1] "CRITICAL"}}'
/etc/cron.d/maldetweeklyCRITICAL

# 6  
Old 01-12-2015
Hello anil510,

Could you please try this and let me know this helps.(Not tested though)
Code:
A=`grep -rl  maldet /etc/cron*`
echo $A | awk '{split($0, X, " ");}END{if(length(X)== 1){print "OK"} else if(length(X)==0){print "NO results found."} else {print "CRITICAL\nResults found are:";for(i in X){print X[i]}}}'

I have mentioned as Results found are: you can remove this if it doesn't require.

Thanks,
R. Singh
# 7  
Old 01-12-2015
I have found the solution.

Code:
multimalcron=`grep -rl  maldet /etc/cron* | grep -v maldet_daily`

if [ "$(echo $multimalcron)" ]; then
                echo " Multiple maldet cron found: echo $multimalcron"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To get or print specific value in result

i am executing below code to achive my result, but for second row the value is not coming it should come URL like other two . url start with http:// and end with .xhtml cat FILE | grep 'Test failed' | awk -F',' '{print $3,$8,$12}' INPUT 1517679173303,84,SKILLED LANGUAGE - ENTER... (11 Replies)
Discussion started by: mirwasim
11 Replies

2. Shell Programming and Scripting

Need help in solving to obtain desired print output using awk or perl or any commands, Please help!!

I have an file which have data in lines as follows ad, findline=24,an=54,ab=34,av=64,ab=7989,ab65=34,aj=323,ay=34,au=545,ad=5545 ab,abc,an10=23,an2=24,an31=32,findline=00,an33=23,an32=26,an40=45,ac23=5,ac=87,al=76,ad=26... (3 Replies)
Discussion started by: deepKrish
3 Replies

3. Shell Programming and Scripting

awk split command to get the desired result

Dear all, I am using the awk 'split' command to get the particular value. FILE=InputFile_009_0.txt Temp=$(echo $FILE | awk '{split($FILE, a, "e_"); print a}') I would like to have the Temp take the value as : _009_0 ... (4 Replies)
Discussion started by: emily
4 Replies

4. UNIX for Dummies Questions & Answers

Print result of mv -n

I am trying to move files which donot have same filename using find /Users/ParijatMac/desktop/unix/new_dir -type f -mmin +"$HRS" -exec mv -n "{}" /Users/ParijatMac/desktop/unix/old_dir \; -print but i am getting all filenames including the ones with duplicate names.Please help me to sort... (5 Replies)
Discussion started by: parijat guh
5 Replies

5. Shell Programming and Scripting

Print Value between desired html tag

Hi, I have a html line as below :-... (6 Replies)
Discussion started by: satishmallidi
6 Replies

6. UNIX for Dummies Questions & Answers

How to print the line from the file in the desired format:?

I am reading a file of Linux ( like mentioned below) & the data is represented in a single line like mentioned below: 11/03 4:00 39992 0.098 5.195 0.034 0.001 1.091 182 0.000 0 0.071 4.252 0.033 0.001 666.53 Now i want to print the result in other file something like this :- 39992... (5 Replies)
Discussion started by: Anamica
5 Replies

7. UNIX for Dummies Questions & Answers

Help me in getting the desired result

Hi All, I have input file which is pipe delimited A | 1 B | 2 c | 3I need output of displaying total number of lines in a file as last column. A | 1 | 3-----total number of linesin file. B | 2 | 3 c | 3 | 3 (9 Replies)
Discussion started by: pravinashwin
9 Replies

8. Shell Programming and Scripting

Use the print result of a script as an argument

Hi all, Say I have a script named script.sh. What it does is to print a line like "abc" #! /usr/bin/ksh print "abc" I would like to pass this value to an external variable, var1="script.sh" However when I echo $var1 I got "script.sh" itself instead of the result? Thanks (3 Replies)
Discussion started by: isaacniu
3 Replies

9. Shell Programming and Scripting

print out result from data file

i got a data file which contains all the pid,ppid,user,command,pcpu,start_time,status. I wanted to display out the pcpu which is greater than 0. i uses awk'{if($5 > 0){print}}' filename.txt but is printing out result which not i wanted. Is there any way which i can print out those pcpu which is... (8 Replies)
Discussion started by: thms_sum
8 Replies

10. Shell Programming and Scripting

print a function result in new file

Hi, i have a function which return a variable . serach ( paramatere) when i excute this function i get the result in the shell, i want to print this result in a file by calling just the function. how can i do it.. the code example is like that: search ( ) { .. } the call... (0 Replies)
Discussion started by: kamel.seg
0 Replies
Login or Register to Ask a Question