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 > extracting the value of variable !!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-10, 14:18
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
extracting the value of variable !!

Hello Dear,

I have a variable defined in the file as

DATA_SPACE=df -k $data_dir | tail -1 | awk '{print $5}' | awk -F% '{print $1}'

I want to print this value which basically gives the disc space at the specified data_dir .


If I say $DATA_SPACE its giving me the string df -k $data_dir | tail -1 | awk '{print $5}' | awk -F% '{print $1}'
but I want to get the value of it .

If I execute the df -k $data_dir | tail -1 | awk '{print $5}' | awk -F% '{print $1}' at command prompt its giving me the value of diskspace specified for data_dir as some value example 86 - ie diskspace available in $data_dir is 86%


$data_dir is an environment variable.

thanks/mahesh
Reply With Quote
  #2 (permalink)  
Old 01-18-10, 16:13
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Hello Dear

Try the following but note carefully the type of quote around the whole thing:
Code:
DATA_SPACE=`df -k $data_dir | tail -1 | awk '{print $5}' | awk -F% '{print $1}' `
Out of curiosity how many of you use this MIKELALA account?
Reply With Quote
  #3 (permalink)  
Old 01-18-10, 16:20
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
I am learning and in project purely on unix development and I am not having ample exp on unix ksh programming thats why u see lots of questions from me ....I saw only dbforums website where their is a prompt and correct reply so I love to post any issues and their is immediate response too ..

Thanks for asking . I am the only one user ..

Can you please advice me a good book on KSH Programming.

your advice to put backquotes didn't worked as such -.

The thing is that all the variable are defined in .ini file and i am reading the .ini file to get the value of the variable ..


Rgds/mike

Last edited by MIKELALA; 01-18-10 at 16:34.
Reply With Quote
  #4 (permalink)  
Old 01-18-10, 17:30
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
You need to start with little steps.
Try
Quote:
date
DATA_SPACE=`date`
echo $DATA_SPACE

second example:
ls
LIST=`ls`
echo $LIST
Note that on line 2 the command date is enclosed by the "backtick" character. This character and the 'tilde', '~' character usually occupy the upper left key on the typewriter portion of the keyboard.
It is also important not to put spaces before and after the equal sign.
When you are writing a script, you can test each command that is in the script at the command prompt until you get the correct syntax.

google "ksh tutorial" for guidance.

Last edited by kitaman; 01-18-10 at 17:43.
Reply With Quote
  #5 (permalink)  
Old 01-18-10, 18:20
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Mahesh, I was just confused - previously you signed your name as Mike.

Your command shows the disk usage
Code:
df -k $data_dir
If you want the 4th column showing space available in blocks then take the last line and just how colukmn 4:
Code:
df -k $data_dir | tail -1 | awk '{ print $4;}'
To put this in a variable:
Code:
DATA_SPACE=`df -k $data_dir | tail -1 | awk '{ print $4;}'`
echo $DATA_SPACE
I used the book Unix Programming Environment and found it very useful - but there may be better books these days. If you do get the book then buy it 2nd hand.

Mike

Last edited by mike_bike_kite; 01-19-10 at 04:25.
Reply With Quote
  #6 (permalink)  
Old 01-19-10, 04:34
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
maybe you want
eval $DATA_SPACE
Reply With Quote
  #7 (permalink)  
Old 01-26-10, 23:03
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
Thanks - It worked.
eval=$DISC_SPACE

mike
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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