Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009
    Posts
    1

    Unanswered: Storing variables in a shell script for reporting later

    I am writing a Unix Shell script to perform different system checks and balances based on criteria requirements from vendor. Things like checking for adequate diskspace, sufficient RAM, etc. I have at each stage of verification variables set so for RAM I have variable $MEM, CPU I have set as $PROC. My question is how to store these variables until the time is to report them out to a .csv file ?? (I understand Perl would handle this differently, but I do not know Perl language)

    Any assistance would be helpful..
    Thanks !!

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    There are many ways but this is just one method. Save the variable values in a file as code so that the file can be included by any other shell and those variable values read. This program saves 2 variables to a file (tmp.dat).
    Code:
    #!/bin/sh
    
    # init var
    VAL_1=123
    VAL_2=567
    
    echo VAL_1=$VAL_1 > tmp.dat
    echo VAL_2=$VAL_2 >> tmp.dat
    
    exit
    This will create a file tmp.dat that looks like this. Be aware you will need quotes if your values contain strings.
    Code:
    VAL_1=123
    VAL_2=567
    Any other program could then read those variable values by just including that file:
    Code:
    #!/bin/sh
    
    . tmp.dat
    
    echo $VAL_1
    echo $VAL_2
    
    exit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •