Shell Script to check dhcp conf file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to check dhcp conf file
# 1  
Old 07-13-2015
Shell Script to check dhcp conf file

Hi,

I have to prepare a script to check the dhcp conf file. The script has to check for a specific parameter called circuit ID. If the Circuit ID is unique it should show the output that it is unique and if it is duplicate it should show that the Circuit ID is duplicate. I have prepared the below script but every time i enter a unique Circuit ID it still shows that it is duplicate. Please, help
Code:
#!/bin/bash

echo -e "Please enter the Circuit ID : \c"
read CID
CMD="find . -type f -exec grep -H "'$CID'" {} \;"
CNT="$CMD | wc -l"
eval $CNT
read Z


if [ "$Z" != 0 ] ;
then
echo " the Circuit ID : $CID is duplicate "
echo " Please find below the list where the Circuit ID is present :"
eval $CMD
exit 0
else
echo " the Circuit ID : $CID  is unique. "
fi

# 2  
Old 07-13-2015
I'm not sure how the script should fit the verbal description you have given.

While you say you want to check one single file, you run a find across ALL files (no matter what their contents/meaning might be) in the current directory and all subdirectories grepping for the circuit ID.
Then you read Z - from stdin! Nothing to do with your results so far.
And, why should anything be unique when its count is zero?
# 3  
Old 07-13-2015
Dear Rudi,

The script in placed in /etc/dhcp directory, so the find commandin expected to read the dhcp conf file. the Count is taken in case multiple entries of the same Circuit ID are found.

I get that the variable "$Z" is not gtting me anywhere. Please suggest something

Thanks
Nix
# 4  
Old 07-13-2015
How about
Code:
 [ $(grep -c "$CID" dhcp.conf) -gt 1 ] && echo duplicate || echo unique

This does not cover the case that CID is not found at all.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 07-13-2015
Dear Rudi,

Thanks, a lot for all the help. I appended the script and got the desired result

Code:
#!/bin/bash


echo -e "Please enter the Circuit ID : \c"
read CID
[ $(grep -c "$CID" dhcp.conf) != 0 ] && echo " the Circuit ID : $CID is duplicate " || echo " the Circuit ID : $CID  is unique. "
echo -e "Please enter Subnet mask: \c"
read SB
if [ "$SB" != 255.255.224.0 ]
then
echo " The Subnet Mask is not /19 as per requirement. Please correct it "
else
echo " The Subnet Mask is /19 which is required "
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to check a file

I'm required to write a simple shell script that when it runs it writes the output which is a simple barcode to a tmp flat file which I can do the bit I'm struggling with... The next time it runs I need to check the tmp output file to see if that barcode is in the output file and if it is send... (5 Replies)
Discussion started by: worky
5 Replies

2. UNIX for Beginners Questions & Answers

Changes in dhcpd.conf do not make a difference in DHCP service behaviour

Hi Experts, Our DHCP server currently answers the DHCP Discover requests from ServerX. In our dhcpd.conf file there are parameters defined for ServerX. Now we introduced some additional Servers into the network and want them to get service from the same DHCP server. Similar configuration... (13 Replies)
Discussion started by: ekorgur
13 Replies

3. UNIX for Dummies Questions & Answers

Need shell script to check file

Hi Experts, I am not good in writing script. Just stared.I am looking for shell script to check following parameters. 1) Number of files on remote Linux SUSE server.- Any directory and sub directory. 2) I should define number of files in script. Files should be variable. 3) Age of... (2 Replies)
Discussion started by: ApmPerfMonitor
2 Replies

4. Shell Programming and Scripting

How to check the duplicancy of file using shell script?

Hi all, i am getting the file through sftp from a location in the name of 20141201_file.txt (iam getting the file on daily basis with date appended at the beginning) so before going to my actual process ,i want to check whether today files and yesterday file are same or not(which i used to... (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

5. Shell Programming and Scripting

How to check file name format using shell script?

Hi, I am writting a script, which accepts input file as parameter. Input file name is aa_bb_cc_dd_ee.<ext> I need to check that input file name should be of 5 fileds. Please help me out. :confused: (7 Replies)
Discussion started by: Poonamol
7 Replies

6. Shell Programming and Scripting

Need to check for empty file in C shell script

I am running a C shell script. I have an output file from a previous step and I need to run "something" in the next step to check if the file is empty. If the file is empty, then the job script should finish EOJ. If the file is not empty then the job script should abend. Please help Thanks. (4 Replies)
Discussion started by: jclanc8
4 Replies

7. Shell Programming and Scripting

need to check the file using ftp in a shell script

i need to write a shell script.. connecting to another server using ftp and check whether the file ter.txt is exists there or not. i have written scirpt partially,as i new to Unix. ftp -inv $FTPHOST > $TEMPFILE1 2> $TEMPFILE1 << EOF user $FTPUSER $FTPPW binary prompt ${CD} ls *.txt... (11 Replies)
Discussion started by: KiranKumarKarre
11 Replies

8. Shell Programming and Scripting

File System Check using shell script !!!

Hi Guys I m posing this new thread as I didnt get satisfactory result after running search here. My requirement is very simple (using shell script) I need to findout what all file systems are mounted -> Then I need check the health of that file system - by disk usage & by doing a simple... (8 Replies)
Discussion started by: csaha
8 Replies

9. Solaris

Solaris Install over WAN(where to keep wanboot.conf file for DHCP client)

I am trying to configure my jumpstart server to install Solaris 10 on a T1000 machine(target) over WAN. I do not know the IP address of the client, i wish the client to get the IP address from DHCP. how do i configure my /etc/netboot hierarchy. One option would be to keep the wanboot.conf in... (1 Reply)
Discussion started by: hemalsid
1 Replies

10. Shell Programming and Scripting

delete dhcp.conf entry using sed

I am trying to use sed to remove entries from my dhcpd.conf file. The form of the file is: host foo { option 1 option 2 } host bar { option 1 option 2 } I was trying to use a label like: sed -e :a -e "s/^host bar {*//g;/{/N;//ba" /etc/dhcpd.conf... (2 Replies)
Discussion started by: tizatron
2 Replies
Login or Register to Ask a Question