Help with hp configuration script (ksh)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with hp configuration script (ksh)
# 1  
Old 01-15-2010
Help with hp configuration script (ksh)

Hi
I am writting a configuration script to make changes to the /etc/rc.config.d/nddconf file. I have pulled this section out to test it so I have the editing of the file already written.

I have two problems with the function.
1. The script is ignoring the results of the if loop.
2. The sed line doesn't delete

Code:
function test_ndd {
cd /tmp/PCI
cp /etc/rc.config.d/nddconf /tmp/nddconf
 
for ndd1 in $(<nddentries)
do
  if [ $(grep -c "$ndd1" /tmp/nddconf)!=0 ]
# This line is meant to check to see if the file already contains $ndd1 if it 
# does I need it to delete it from the list
  then
    echo " needs adding !"
  else
    echo $ndd1
    sed -e /"$ndd1"/d nddentries
# This line is meant to delete it from the nddentries list.
  fi
done
}
test_ndd

nddentries file contains
Code:
tcp_syn_rcvd_max
arp_cleanup_interval
ip_forward_src_routed
ip_forward_directed_broadcasts
ip_respond_to_timestamp
ip_respond_to_timestamp_broadcast
ip_respond_to_address_mask_broadcast
ip_respond_to_echo_broadcast
ip_forwarding

Here is the result of running the script
Code:
[root@testing] # ./test_ndd.sh
+ test_ndd
+ count=1
+ cd /tmp/PCI
+ grep -c tcp_syn_rcvd_max /tmp/nddconf
+ [ 0!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c arp_cleanup_interval /tmp/nddconf
+ [ 2!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c ip_forward_src_routed /tmp/nddconf
+ [ 1!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c ip_forward_directed_broadcasts /tmp/nddconf
+ [ 1!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c ip_respond_to_timestamp /tmp/nddconf
+ [ 2!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c ip_respond_to_timestamp_broadcast /tmp/nddconf
+ [ 1!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c ip_respond_to_address_mask_broadcast /tmp/nddconf
+ [ 1!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c ip_respond_to_echo_broadcast /tmp/nddconf
+ [ 1!=0 ]
+ echo  needs adding !
 needs adding !
+ grep -c ip_forwarding /tmp/nddconf
+ [ 1!=0 ]
+ echo  needs adding !
 needs adding !
[root@testing] #

Thank you for looking !

Last edited by Franklin52; 01-15-2010 at 12:38 PM.. Reason: Please use code tags!
# 2  
Old 01-15-2010
Code:
# if [ $(grep -c "$ndd1" /tmp/nddconf)!=0 ]
# Why not :
if grep "$ndd1" /tmp/nddconf

Code:
# sed -e /"$ndd1"/d nddentries
# Why not :
sed "/$ndd1/d" nddentries


Last edited by frans; 01-16-2010 at 10:57 AM.. Reason: remove brackets
# 3  
Old 01-16-2010
Thank you for your response I will test it on Monday when I am back in the office and let you know the results.
# 4  
Old 01-16-2010
You should put spaces around the !=
Code:
if [ $(grep -c "$ndd1" /tmp/nddconf) != 0 ]
then

Alternatively:
Code:
if grep "$ndd1" /tmp/nddconf > /dev/null
then

Quote:
Originally Posted by frans
Code:
if [ grep "$ndd1" /tmp/nddconf ]

I get
Code:
binary operator expected

# 5  
Old 01-16-2010
Quote:
Originally Posted by Scrutinizer
I get
Code:
binary operator expected

Smilie Of course, i forgot to remove the brackets around ! Smilie
# 6  
Old 01-18-2010
Sadly that didn't work either although I have noticed that it is picking up the commented out examples earlier in the file so I need to exclude lines beginning with a # as well.

Looking to see what other options I can use.

I am not set on using if and sed. (although it is annoying as they should work! )
# 7  
Old 01-18-2010
You could probably use this:
Code:
if grep "^[^#]*$ndd1" /tmp/nddconf >/dev/null
then

Or perhaps you could give this a try as an alternative for the script:
Code:
cd /tmp/PCI
cp /etc/rc.config.d/nddconf /tmp/nddconf
awk -F= 'NR==FNR {if($1!~/^#/)A[$2]=1;next}!A[$1]' /tmp/nddconf nddentries > nddentries.missing


Last edited by Scrutinizer; 01-18-2010 at 07:08 PM.. Reason: Wrong grep and wrong awk were not working. Corrected mistake
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script to save configuration from a router

Hy guys, My name is Alex, i am new here and I hope to find some answers. I am trying to run a expect script to telnet to a mikrotik router, run a command (export), and save the output of that commant to a file (outputfile.txt). The problem is that only part of the output is saved to... (2 Replies)
Discussion started by: axexandru
2 Replies

2. Shell Programming and Scripting

Script/SQL configuration

i have a field in a record which is varchar2(180) and i have stored 180 characters in it when i query record for the value from sqldeveloper, it is coming properly when i connect from UNIX and try to query the field, i am getting in 3 lines instead of displaying in 1 line SHELL SCRIPT : sqlplus... (3 Replies)
Discussion started by: vkca
3 Replies

3. Shell Programming and Scripting

configuration for ftp script in main script

Hi, I am new to shell scripting,and i was planning to write a script that will FTP files to destination folder. I was planning that All configuration should be done through a properties files. and finally the output should be Files are transferred I have developed a properties file named... (4 Replies)
Discussion started by: rahul125
4 Replies

4. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

5. UNIX for Advanced & Expert Users

Script to get system configuration

Hi, We have >1000 UNIX boxes in our environment with various UNIX flavors like Solaris, HP-UX and Redhat Linux ES 3/4/5. We need to collect their system configuration like - No. of CPUs and their frequencies - RAM Size - No. of HDDs installed and their usage - Exact OS Version and its... (3 Replies)
Discussion started by: prvnrk
3 Replies

6. Shell Programming and Scripting

Match configuration files with a script

Hi all, Can you help me make a script(ksh-Solaris 8) that will match two configuration files? I have some problems with sed newline. The script should at least match the value of parameters from one file to another, which looks always like this: parameter1=some_value... (3 Replies)
Discussion started by: majormark
3 Replies

7. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

8. Shell Programming and Scripting

tracing a ksh script within a ksh script

I normally trace a script with the ksh -x <script name> and redirect strderr to file. But if you have a script like the examble below...... vi hairy bear=`grep bear animals` if then ksh more_animals fi If I ksh -x hairy it won't trace "more_animals" unless I put a -x in it. Is... (1 Reply)
Discussion started by: shorty
1 Replies

9. Shell Programming and Scripting

executing a ksh script from another ksh script

Hi, I'm new to unix scripting.How can i call a script from another script. I have a.ksh and b.ksh .I have to call b.ksh from a.ksh after it is successfully exceuted. I tried using #!/bin/ksh -x in a.ksh and at the end i have used /path/b.ksh My problem is it is executing only a.ksh.it... (6 Replies)
Discussion started by: ammu
6 Replies

10. Shell Programming and Scripting

script to read configuration file

Hi, I would like to write a Korn shell script which will remove files older than a certain date. In my script, it will read a configuration file with the following entries: # <directory> <filename wildcard> # /home/philip/log *.log /home/philip/log1 delete-me*.log The... (1 Reply)
Discussion started by: philip_dba
1 Replies
Login or Register to Ask a Question