Print if found non-desired result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print if found non-desired result
# 8  
Old 01-12-2015
Quote:
Originally Posted by anil510
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

Hello anil510,

As per your requirement in Post#1, you have asked that you need to print ok when it is only single entry in cron, the code which is provided by you will not satisfy that condition, also I have added a condition if no entry found for maldetthen it will show that. Could you please try code which I provided you in Post#6, let me know if that helps you.


Thanks,
R. Singh

Last edited by RavinderSingh13; 01-12-2015 at 03:54 AM.. Reason: Added 2 icode tags
# 9  
Old 01-12-2015
The following seems to provide something closer to the spirit of what was requested in the original post in this thread (and, except for the one call to grep, only uses shell built-ins):
Code:
list="$(grep -rl 'maldet' /etc/cron*)"
if [ "$list" = "/etc/cron.d/maldet_daily" ]
then	echo 'OK:'
else	if [ "$list" = '' ]
	then	echo 'critical: maldet not found:'
	else	printf 'critical: maldet cron found in the following file(s): '
		last=''
		echo "$list" | while read line
		do	if [ "$last" != '' ]
			then	printf '%s -- ' "$last"
			fi
			last="$line"
		done
		printf '%s\n' "$last"
	fi
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