Best Alternative for checking input parameter contains required value or not


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Best Alternative for checking input parameter contains required value or not
# 8  
Old 06-10-2015
Then you can get it with awk:
Code:
if [ "`awk -F"[ =]+" '$1=="net.ipv4.icmp_echo_ignore_broadcasts" {print $2}' results.txt`" = "1" ]
then
...

This User Gave Thanks to MadeInGermany For This Post:
# 9  
Old 06-10-2015
Quote:
What I want to do is that it will display 'T' if it has and value return and 'F' if no return.
Code:
Hi I just tried and it manage to give me the output.


Code:

/sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep -q "= 1" && echo T || echo F
T

Do you mind explain the && echo T || echo F means?

Another other better ways?

Beg your pardond, its exactly what you asked for.
Quote:
The results are already piped to results.txt , I would need to check if net.ipv4.icmp_echo_ignore_broadcasts = 1 is contained in the text file contains exactly.
net.ipv4.icmp_echo_ignore_broadcasts = 1 so that I can check whether it is 'T' or 'F'
You seem to like to do your work twice, i dont.
# 10  
Old 06-10-2015
change

Hi Sea,

Doing work twice is because there is a constraint( the client has already return me with the output) in another text file.

MadeInGermany,

I have a change request, each output is identified with a unique ID, 4.2.5 Enable Ignore Broadcast Requests , the next input is goes by 4.2.6 Enable Bad Error Message Protection, I would like to read the line in blue to check if it contains the required parameter or not.

Code:

4.2.5 Enable Ignore Broadcast Requests
net.ipv4.icmp_echo_ignore_broadcasts=1

4.2.6 Enable Bad Error Message Protection
net.ipv4.icmp_ignore_bogus_error_responses = 1

Thanks.

Prior to this it has already been send to results.txt

Code:
echo -e "4.2.5 Enable Ignore Broadcast Requests" >> /tmp/results.txt
/sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts >> /tmp/results.txt


Last edited by alvinoo; 06-10-2015 at 10:26 PM..
# 11  
Old 06-11-2015
Hi,

I have another question, how do I check if between a segment in the file contains the word, hard core 0 & fs.suid_dumpable = 0 at the same time, I tried using .* operator in Unix but it works for same line only

Code:
cat $file | awk '/4.2/ {P=0} /4.1/ {P=1} P' | grep -iq -E "hard core 0" && echo T || echo F
cat $file | awk '/4.2/ {P=0} /4.1/ {P=1} P' | grep -iq -E "fs.suid_dumpable = 0" && echo T || echo F

# 12  
Old 06-12-2015
Try (untested)
Code:
awk '
/4.2/                           {P=0}
/4.1/                           {P=1} 
(/fs.suid_dumpable = 0/ ||
        /hard core 0/)  && P    {L=1}    
END                             {print L?"T":"F" }
' $file

# 13  
Old 06-12-2015
I have no idea what you're trying to do from your latest description???

What does your input look like now?

I would have guessed that you're looking for both a case insensitive match on fs.suid_dumpable = 0 AND a case insensitive match on hard core 0. RudiC's code assumes you're trying to print T if you get a case sensitive match on either (not necessarily both) of those strings.

What output are you trying to produce from that input?

Are you just looking for a way to produce the same output (two lines with either T or F) as your last two command lines in post #11 in this thread without reading and writing parts of your input file ten times?
# 14  
Old 06-18-2015
Quote:
Originally Posted by MadeInGermany
Code:
command1 && command2 || command3

Run command1; if its exit status is 0(=true), run command2.
If the exit status of command1 or command2 is not 0(=false), run command3.
Quick and dirty for
Code:
if command1; then command2; else command3; fi

where the exit status of command2 does not matter.
--
Smilie OMG what a hack!
Hi MadeInGermany,

will it be possible to display the T,F value and the output at the same time,
for example.

Code:
1.1.1.3.1.1.1; File System No Auditing ;T
1.1.1.3.1.1.2 Handle Manipulation No Auditing ;T
1.1.1.3.1.1.3; Filtering Platform Packet Drop No Auditing ;T
1.1.1.3.1.1.4; Certification Services No Auditing ;T

So far what I have tried is something like these. But would appreciate if someone can give me a shorter alternatives.

Code:
echo "1.1.1.3.1.1.1;"    `var=$(awk '/Privilege Use/ {P=0} /Object Access/ {P=1} P' AdvancedAudit.txt | grep -ia 'File System') ; echo $var; echo $var | grep -iq "No Auditing" && echo ';T' || echo ';F' ` 
echo "1.1.1.3.1.1.2"    `var=$(awk '/Privilege Use/ {P=0} /Object Access/ {P=1} P' AdvancedAudit.txt | grep -ia "Handle Manipulation") ; echo $var; echo $var |  grep -iq "No Auditing" && echo ';T' || echo ';F'` 
echo "1.1.1.3.1.1.3;"    `var=$(awk '/Privilege Use/ {P=0} /Object Access/ {P=1} P' AdvancedAudit.txt | grep -ia "Filtering Platform Packet Drop"); echo $var; echo $var | grep -iq "No Auditing" && echo ';T' || echo ';F'` 
echo "1.1.1.3.1.1.4;"    `var=$(awk '/Privilege Use/ {P=0} /Object Access/ {P=1} P' AdvancedAudit.txt | grep -ia "Certification Services" ) ; echo $var; echo $var | grep -iq "No Auditing" && echo ';T' || echo ';F'`


Last edited by alvinoo; 06-18-2015 at 03:21 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Any alternative for mmin or cmin parameter

Hi, I need to write a shell script where I need to check whether log file is generated in last 1 hour or not. But I am getting below error in using mmin or cmin parameter with find command: find: bad option -mmin find: bad option -cmin So my concern is that any alternative for mmin option... (5 Replies)
Discussion started by: Ankit Srivastav
5 Replies

2. UNIX for Advanced & Expert Users

Alternative to sort -ur +1 required

I've got scripts trawling the network and dumping parsed text into files with an Epoch timestamp in column 1. I append the old data to the new data then just want to keep the top entry if there is an identical duplicate below (column 1 needs to be ignored). sort -ur +1 works a treat on a Solaris... (16 Replies)
Discussion started by: Mike Smith
16 Replies

3. Shell Programming and Scripting

help with script parameter checking based on environment

I need to check if the parameters are correctly passed based on the Environment I am in. For e.g when I am in dev the 1st paramter needs to be either A OR B OR C OR D similarly when I am in qa the parameter needs to be either e or f so i need to write a case staement or a if statement to... (1 Reply)
Discussion started by: dsravan
1 Replies

4. Shell Programming and Scripting

Checking the required columns in File

Hello Experts, File contains 10 columns with | delimeter. 1,3,4,5,7,9 columns are required columns means it should contains values. i need those records, rest of it will contain or not contain data. test1.txt: a@a.com|a|b|c|d|e|f|g|h|i |a|b|c|d|e|f|g|h|i b@b.com|a||c|d|e|f|g|h|i... (7 Replies)
Discussion started by: muralikri
7 Replies

5. Shell Programming and Scripting

Checking required columns in the file

Hi, File contains with TAB delimeter file,i want check the 2,3 are not null test1@gmail.com 100 test test2@gmail.com 101 test test3@gmail.com test test4@gmail.com 102 OUTPUT test1@gmail.com 100 test test2@gmail.com 101 test Please help me with one single command in... (2 Replies)
Discussion started by: muralikri
2 Replies

6. UNIX for Dummies Questions & Answers

checking if parameter passed is a number

I have written a function that fills an array and another function where if a parameter is supplied it will jump to that part of the array and cat it to the screen. I need to put in some checks to make sure the parameter supplied is firstly a number and then not a number great than the length of... (2 Replies)
Discussion started by: magnia
2 Replies

7. Shell Programming and Scripting

Greping the required parameter...

Hi Friends, Urgently required to know this : I have a file which has several stanzas like below : CuDv: name = "hdisk3" status = 1 chgstatus = 2 ddins = "scdisk" location = "03-08-01-11,0" parent = "scsi1" connwhere =... (3 Replies)
Discussion started by: vijaya2006
3 Replies

8. UNIX for Dummies Questions & Answers

checking parameter values passed to script

Hi, I will pass 3 parameters for a script.I have to check the file name and create a new file name with time stamp. the parameters which i'm passing are /dir/stg/filename.txt /dir/path/head.txt /dir/path/tail.txt Now i have to check filename like : if it is a.txt i have to create... (2 Replies)
Discussion started by: ammu
2 Replies

9. Shell Programming and Scripting

Parameter Checking

Hi all, My script has 2 mandatory and 1 optional paramter. If the third parameter(optional) one is null the it should take a default value say 3. Can any one please write a simple code. sh test.sh 1 2 3 var1=$1 var2=$2 if then var3=3 fi echo " the third variable $var3" ... (1 Reply)
Discussion started by: ammu
1 Replies

10. Shell Programming and Scripting

Help required to pass the parameter

i am calling a pl/sql procedure through a shell script, there is one IN and 2 OUT parameter required to pass to the procedure to execute.. My procedure is XX_CITIDIRECT_EXP_PKG.main_proc and In parameter is p_period which I wanto to pass 'MAY-06'. Can anyone figure out, whats is wrong here ... (4 Replies)
Discussion started by: u263066
4 Replies
Login or Register to Ask a Question