By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,562 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,562 IT Pros & Developers. It's quick & easy.

Shell Script to List Node Definitions

Colloid Snake
100+
P: 144
Hello everyone-

I am working on a shell script to parse out a Node.def file that contains the hostname, version, IP address, and date updated. There is a separate .def file for each node (of which there are several hundred), and each node is in a separate directory.

I am attempting to extract the node name and IP address from each .def file and compile these into a single file, but I'm getting an error, no matter what I alter, so I think I'm just not setting this up properly. Can anyone help?

Expand|Select|Wrap|Line Numbers
  1. echo "`date` - List of names and correlating IPs for `hostname`" > SensorList.txt
  2.  
  3. set file_list = `find . -name "*.def" -type f`
  4.  
  5. for $file in file_list 
  6.    # extract name and ip from file
  7. do
  8.    `cat $file | grep "NAME=*"` >> SensorList.txt
  9.    `cat $file | grep "IP=*"` >> SensorList.txt
  10. done
  11.  
Error:
# ./CreateSensorList.sh
./CreateSensorList.sh: file_list: command not found
cat: file_list: No such file or directory
cat: file_list: No such file or directory

I have attempted to move around the `` to encompass different things, add/remove the $ in the for, etc... And I'm currently out of ideas, so any help would be appreciated.
May 6 '08 #1
Share this Question
Share on Google+
2 Replies

ashitpro
Expert 100+
P: 542
Hello everyone-

I am working on a shell script to parse out a Node.def file that contains the hostname, version, IP address, and date updated. There is a separate .def file for each node (of which there are several hundred), and each node is in a separate directory.

I am attempting to extract the node name and IP address from each .def file and compile these into a single file, but I'm getting an error, no matter what I alter, so I think I'm just not setting this up properly. Can anyone help?

Expand|Select|Wrap|Line Numbers
  1. echo "`date` - List of names and correlating IPs for `hostname`" > SensorList.txt
  2.  
  3. set file_list = `find . -name "*.def" -type f`
  4.  
  5. for $file in file_list 
  6.    # extract name and ip from file
  7. do
  8.    `cat $file | grep "NAME=*"` >> SensorList.txt
  9.    `cat $file | grep "IP=*"` >> SensorList.txt
  10. done
  11.  
Error:
# ./CreateSensorList.sh
./CreateSensorList.sh: file_list: command not found
cat: file_list: No such file or directory
cat: file_list: No such file or directory

I have attempted to move around the `` to encompass different things, add/remove the $ in the for, etc... And I'm currently out of ideas, so any help would be appreciated.



please have a look at following script..it should work

Expand|Select|Wrap|Line Numbers
  1.  
  2. echo "`date` - List of names and correlating IPs for `hostname`" > SensorList.txt
  3. file_list=`find . -name "*.def" -type f`
  4. for file in $file_list
  5. # extract name and ip from file
  6. do
  7.   echo $file
  8.   `cat $file | grep "NAME=*"` >> SensorList.txt
  9.   `cat $file | grep "IP=*"` >> SensorList.txt
  10. done
  11.  
  12.  
check out the second line.
you don't have to use 'set' to initialize the local variable..it is used to set the environmental variables.
Don't put spaces before and after '=' operator.
In third line use '$file_list' instead 'file_list'

Rest is fine.....
May 7 '08 #2

Colloid Snake
100+
P: 144
Ah, thank you very much! I also removed both of the `` around the cat $file... lines to get it to run (and the ='s are in search strings, that's how the file is set up so I left those in) and it's working now.

Thanks again

~Snake
May 7 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.