Shell Script to List Node Definitions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Colloid Snake
    New Member
    • Nov 2006
    • 144

    Shell Script to List Node Definitions

    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?

    [code=shell]
    echo "`date` - List of names and correlating IPs for `hostname`" > SensorList.txt

    set file_list = `find . -name "*.def" -type f`

    for $file in file_list
    # extract name and ip from file
    do
    `cat $file | grep "NAME=*"` >> SensorList.txt
    `cat $file | grep "IP=*"` >> SensorList.txt
    done
    [/code]

    Error:
    # ./CreateSensorLis t.sh
    ./CreateSensorLis t.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.
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by Colloid Snake
    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?

    [code=shell]
    echo "`date` - List of names and correlating IPs for `hostname`" > SensorList.txt

    set file_list = `find . -name "*.def" -type f`

    for $file in file_list
    # extract name and ip from file
    do
    `cat $file | grep "NAME=*"` >> SensorList.txt
    `cat $file | grep "IP=*"` >> SensorList.txt
    done
    [/code]

    Error:
    # ./CreateSensorLis t.sh
    ./CreateSensorLis t.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

    Code:
    echo "`date` - List of names and correlating IPs for `hostname`" > SensorList.txt
    file_list=`find . -name "*.def" -type f`
    for file in $file_list
    # extract name and ip from file
    do
      echo $file
      `cat $file | grep "NAME=*"` >> SensorList.txt
      `cat $file | grep "IP=*"` >> SensorList.txt
    done
    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.....

    Comment

    • Colloid Snake
      New Member
      • Nov 2006
      • 144

      #3
      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

      Comment

      Working...