LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Generating script functioning similar to df command (https://www.linuxquestions.org/questions/linux-newbie-8/generating-script-functioning-similar-to-df-command-4175462056/)

Amit Kumar Gupta 05-15-2013 05:09 AM

Generating script functioning similar to df command
 
I have to write a script which work behind the df command. How it fetches the information about disk free space.

Also a graphical representation is required.

druuna 05-15-2013 05:15 AM

We don't do the assignment for you, but we are willing to help with the problems you encounter.

What have you tried this far?
Any specific problems you run into?

Amit Kumar Gupta 05-15-2013 05:29 AM

for dir in `ls /home';
do
out = `df /home/$dir`
{
for $out;
do
out2 = `cut -c2-20, 34-45 $out`
echo $out2
done
}
done

I have written this script to fetch information from df and then taking out specific columns out. But the problem is we dont have any control on df output. Is there anyway i can control that?

druuna 05-15-2013 05:36 AM

Are you sure you need to use df for this assignment? I'm asking because df works on file systems ("partitions") and not on files/directories.

The du command on the other hand can handle files/directories.

Unless all the directories in the /home directory are mounted partitions, the above doesn't make too much sense.

Quote:

Originally Posted by Amit Kumar Gupta
But the problem is we dont have any control on df output. Is there anyway i can control that?

Please explain further, what si it you want or expected?

Amit Kumar Gupta 05-15-2013 05:41 AM

Yes df is the command which i am using for this assignment. Because i have to get all the details of the partitions their assigned spaces, free space etc.

druuna 05-15-2013 05:46 AM

Can you post the output of the following command:
Code:

df -HP
You haven't answered my other question in post #4.

Amit Kumar Gupta 05-15-2013 05:54 AM

Filesystem Size Used Avail Use% Mountedon
/dev/sda2 83G 2.6G 76G 4% /
/dev/sda1 49G 89M 46G 1% /Rnd
/dev/sda3 1.1G 24M 95M 3% /boot

druuna 05-15-2013 06:17 AM

Quote:

Originally Posted by Amit Kumar Gupta (Post 4951575)
Filesystem Size Used Avail Use% Mountedon
/dev/sda2 83G 2.6G 76G 4% /
/dev/sda1 49G 89M 46G 1% /Rnd
/dev/sda3 1.1G 24M 95M 3% /boot

I don't see any partitions mounted in the /home directory.

Why do you try to use ls /home? There's no point in doing that.

You can use df to show a specific partition (Example: df -HP /Rnd) or use df -HP and pipe it through awk if you want/need specific fields/lines.

This example will show available space on the /Rnd partition:
Code:

df -HP | awk '/Rnd/ { print $4 }'
Why haven't you answered my other question:
Quote:

Originally Posted by Amit Kumar Gupta
But the problem is we dont have any control on df output. Is there anyway i can control that?

My reply:
Quote:

Originally Posted by druuna
Please explain further, what is it you want or expected?

EDIT: Maybe these will help:
Bash:
Sed and Awk:

Amit Kumar Gupta 05-15-2013 06:56 AM

Yes i accept the answer provided by you.

The problem is i have to generate the similar output with help of a script which does not use df command. As per the question raised by client he wants to control the outpur of df so that he can modify it as per the requirment.

In nutshell, it is writing a script( with some loops or some thing etc.) which genrates o/p similar to df command.

I know i am raising so many questions. Thanks

druuna 05-15-2013 07:07 AM

Quote:

Originally Posted by Amit Kumar Gupta (Post 4951614)
Yes i accept the answer provided by you.

The problem is i have to generate the similar output with help of a script which does not use df command. As per the question raised by client he wants to control the outpur of df so that he can modify it as per the requirment.

In nutshell, it is writing a script( with some loops or some thing etc.) which genrates o/p similar to df command.

Sorry, but you completely lost me.....

Maybe someone else does understand and can come up with an answer.

Amit Kumar Gupta 05-15-2013 07:12 AM

hi druuna,
Thanks for all your help.

I will try to explain once more.

I have to produce similar output as i have provided few posts back.

I have written a script using df command inside it and it gave the similar output as desired but still client said he wants to see similar output without using df command inside the script.

He said make use of some logic and calculate the same result.

Regards
Amit Gupta

chrism01 05-15-2013 08:33 AM

This
Quote:

client said he wants to see similar output without using df command inside the script.
doesn't make any sense at all.
Either the client is insane or this is really an interview or academic qn.
Why on earth wouldn't you use the best tool for the job???

Hint: You could calc it from fdisk

Amit Kumar Gupta 05-15-2013 08:44 AM

Hi chrism,
You got it right. Client has given me some taks to complete so that he can take me in his project.
I have given him the o/p first with usring commands then he said he does not want to use any commands.

Beig very new to Unix i am not able to do it. As i am a functional person but due to some issues trying to equip myself with some tools in my career.

Regards
Amit

chrism01 05-15-2013 08:50 AM

In future, please be totally clear about this sort of thing :)

I think you need to bookmark/read
http://rute.2038bug.com/index.html.gz
http://www.linuxhomenetworking.com/
www.linuxtopia.org

Definitely install Linux at home & practice, practice, practice.

rknichols 05-17-2013 10:10 AM

Other than df, the only command that comes to mind for getting overall information about the filesystem is tune2fs with the "-l" option. That will give you values for block size, block count, free blocks, inode count, and free inodes, from which you can calculate the values that df reports. The tune2fs command works on the device containing the filesystem, so you would first have to figure out which device (and it's quite common to use df to do that, so you'd have to find another way), and it needs read permission on the device. Also, tune2fs is obviously specific to the ext2/3/4 filesystems.


All times are GMT -5. The time now is 04:06 AM.