Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2009
    Posts
    56

    Unanswered: 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

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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?

  3. #3
    Join Date
    Nov 2009
    Posts
    56
    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 17:34.

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    You need to start with little steps.
    Try
    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 18:43.

  5. #5
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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 05:25.

  6. #6
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    maybe you want
    eval $DATA_SPACE

  7. #7
    Join Date
    Nov 2009
    Posts
    56
    Thanks - It worked.
    eval=$DISC_SPACE

    mike

Posting Permissions

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