LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-15-2013, 05:09 AM   #1
Amit Kumar Gupta
LQ Newbie
 
Registered: May 2013
Posts: 16

Rep: Reputation: Disabled
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.
 
Old 05-15-2013, 05:15 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
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?
 
Old 05-15-2013, 05:29 AM   #3
Amit Kumar Gupta
LQ Newbie
 
Registered: May 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
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?
 
1 members found this post helpful.
Old 05-15-2013, 05:36 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
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?
 
Old 05-15-2013, 05:41 AM   #5
Amit Kumar Gupta
LQ Newbie
 
Registered: May 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
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.
 
Old 05-15-2013, 05:46 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Can you post the output of the following command:
Code:
df -HP
You haven't answered my other question in post #4.
 
Old 05-15-2013, 05:54 AM   #7
Amit Kumar Gupta
LQ Newbie
 
Registered: May 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-15-2013, 06:17 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Quote:
Originally Posted by Amit Kumar Gupta View Post
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:

Last edited by druuna; 05-15-2013 at 06:18 AM.
 
2 members found this post helpful.
Old 05-15-2013, 06:56 AM   #9
Amit Kumar Gupta
LQ Newbie
 
Registered: May 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-15-2013, 07:07 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Quote:
Originally Posted by Amit Kumar Gupta View Post
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.
 
Old 05-15-2013, 07:12 AM   #11
Amit Kumar Gupta
LQ Newbie
 
Registered: May 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-15-2013, 08:33 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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
 
Old 05-15-2013, 08:44 AM   #13
Amit Kumar Gupta
LQ Newbie
 
Registered: May 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-15-2013, 08:50 AM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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.
 
Old 05-17-2013, 10:10 AM   #15
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,622

Rep: Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577Reputation: 1577
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script similar to service command in Debian mlpa Slackware 12 12-07-2012 03:59 PM
Generating list of options of a command using script backdoor Programming 7 10-02-2011 06:04 AM
pseudo no generator srand generating similar nos every time Ashok_mittal Linux - General 1 02-22-2008 04:56 AM
Trying to work out how to run a script with a start command or something similar helptonewbie Programming 6 05-31-2007 05:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration