variables can not be changed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variables can not be changed
# 1  
Old 08-18-2010
Tools variables can not be changed

I was trying to get the free space using df, however, it can not be obtained. Is there anyone could help me. Here is my code:

Code:
#!/bin/bash

#The free space of the tmp file;
free_space="0"

#Experimental path where the data file is stored into it.
#This path should be provided by the first argument of the shell.
exp_path=$1;

#Parse the input path and get the correct path of experiment
dir_name=$(dirname ${exp_path})
base_name=$(basename ${exp_path})
exp_path=$(echo ${dir_name}${base_name}/)
#echo ${exp_path}


function get_free_space {
    while read output
    do
        line=$(echo ${output} | awk '{print NF}')
        #echo $line
        if [ ${line} -le 1 ]
        then
            read output
            free_space=$(echo ${output} | awk '{print $3}')
            
        fi
        
        echo ${free_space}
    done
    
}


#df -H /tmp | grep -E "^/dev/" | get_free_space

df /tmp | grep -vE "^Filesystem|tmpfs" | get_free_space

echo ${free_space}

When I echo the value of free_space at the end, there is nothing in it...
# 2  
Old 08-18-2010
There is much variation in the format of "df". We need to know what Operating System you have.

On your system what is the unfiltered output from:
Code:
df /tmp

Within the output displayed which number you you want to output - and in what units of storage?
# 3  
Old 08-18-2010
Quote:
Originally Posted by methyl
There is much variation in the format of "df". We need to know what Operating System you have.

On your system what is the unfiltered output from:
Code:
df /tmp

Within the output displayed which number you you want to output - and in what units of storage?
Thanks for your reply.

I am using Fedora 11. And the output of "df /tmp" is:

Code:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_rpc271-lv_root
                      72645928  34341336  34614304  50% /

Thanks
# 4  
Old 08-18-2010
I haven't got Fedora but if I feed your sample output into your script your script sort of works but displays the figure 34614304 (the "free" figure in 1kb blocks).

There is a wider issue with this. The "df /tmp" is returning the free space for the root filesystem "/". This is because "/tmp" is not a mountpoint and does not have an individual space allocation.

Perhaps someone with Fedora can see why the script misbehaves on Fedora.

Last edited by methyl; 08-18-2010 at 10:55 AM..
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash array variables are changed in loop runtime

I am trying to check whether particular host and port are responding or not. I am using below script to check. but node_port array that i am using in loop is getting replaced with previous iteration value. Script and output is given. Please help me to understanding why node_port values are... (5 Replies)
Discussion started by: tmalik79
5 Replies

2. Shell Programming and Scripting

Script to echo "File permissions or ownership changed from required " when accidentally changed.

Hi All, I have to work in the late nights some times for server maintenance and in a hurry to complete I am accidentally changing ownership or permission of directories :( which have similar names ( /var in root and var of some other directory ).:confused: Can some one suggest me with the... (1 Reply)
Discussion started by: shiek.kaleem
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Permissions Changed?

I cannot seem to post within any thread as I require moderator approval. I believe my permissions have been changed and was wondering whats the reason behind this. Thanks. (3 Replies)
Discussion started by: Banned
3 Replies

4. Red Hat

Password not changed!

Hi I am using Fedora 14. I forgot root password of Fedora 14 so I used online help from Fedora website which says by doing rheb silent 1 and then using proper kernel and then using psswd for changing the password I changed it. But after normal booting GUI I am not able to log-on. Can anybody plz... (5 Replies)
Discussion started by: nixhead
5 Replies

5. Shell Programming and Scripting

Timezone not changed.

Hi All, While installing Red Hat Linux, I tried changing the timezone to Japan for testing.But the timezone was not set to Japan. I tried other timezones , but they didn't work as well. I am guessing the problem might be due to some missing rpm.Does anyone has any idea or faced a similar... (1 Reply)
Discussion started by: nua7
1 Replies

6. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

7. UNIX for Dummies Questions & Answers

Who changed a file?

How can I tell what user last updated a file? (1 Reply)
Discussion started by: kirkm76
1 Replies

8. UNIX for Dummies Questions & Answers

I changed PS1 and now ....

Hello I am using Debain Potato and I changed the PS1. When I log in locally everythink is fine, except that when I enter a long row without hitting enter, then it word wraps automatically. And it does it not at the end of the row, it does it in the middle of the row! It also does not writes... (7 Replies)
Discussion started by: Fwurm
7 Replies
Login or Register to Ask a Question