Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-19-2008, 04:28 AM   #1
Registered: Nov 2008
Posts: 46

Rep: Reputation: 15
Help me with a script file

I am using a product in which i declare the install location like :
and it creates folders if they dont already exist. Like if My_Prod exist and Prod_ver doesnt, it creates the later and if the former isn't present, it creates the former one also.
In the install guide, its given to check the disk space available before installing the product so as to be sure that there is already enof space present in the install location selected.
So I have written a script to check the disk space for the folder
so i pass smthing like:

du -s <install_folder>

it gives me the free memory present in the <install_folder>.
The problem with the script I have is that if i pass a folder which doesnt exist, the command throws me an error. So i want to write a logic to check for the <install_folder> presence and then only run the available space command. If the folder isnt present, go a step back (cd ..) and then only check for the folder presence and break. and so on..

So basically i want a loop and break logic for a path provided at a point where the path is existent.

Kindly help
Old 11-19-2008, 04:56 AM   #2
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
From "man du" :

Summarize disk usage of each FILE, recursively for directories.
So, "du" gives you the USED space in a directory. To get the free space you need "df". This is an example script (invoke with " /some/directory"):


while [ $R -ne 0 ]; do
  df $DIR  1>/dev/null 2>&1
  DIR=`dirname $DIR`

df $DIR
It will not do quite everything for you. The output of "df" is human readable, so I would suggest you read "man tail" and "man cut" and "man tr" and figure out a way of extracting from the lines df outputs exactly what you need.


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
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 05:08 PM
Need a shell script to turn a lined file into a comma seperated file Thaidog Linux - General 8 03-08-2008 07:19 PM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM
Create a script to display file name, Inode, and size of any file. Has to be a script JaxsunApex Linux - Newbie 7 01-29-2007 08:15 PM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:43 PM.

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