If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Storing variables in a shell script for reporting later

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-19-09, 17:23
techie048 techie048 is offline
Registered User
 
Join Date: Jun 2009
Posts: 1
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 !!
Reply With Quote
  #2 (permalink)  
Old 06-20-09, 06:12
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On