If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Shell Program error output help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-24-11, 13:18
ch28456 ch28456 is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
Shell Program error output help

I am writing a program to get the amount of blocks a file/directory occupy calling it blc
so if you type:
blc a b c d
it would output the number of blocks occupied by normal files in those directories (added together)
output would be:
WARNING: c could not be accesses
WARNING: d is not a directory
608
i'm going to add my other program to it using
(( numblocks=$(getblocks file1) ))
my other program getblocks:
if test -e "${1}"
then
ls -sd ${1}|sed 's/^ *//'|cut -d' ' -f1
else
echo 0
fi
Reply With Quote
  #2 (permalink)  
Old 04-25-11, 07:32
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Seems to me it would be much simpler to use 'du'

Code:
du -s a b c d
Then add the 4 lines of output to get the grand total.
Reply With Quote
  #3 (permalink)  
Old 04-25-11, 08:54
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Also what is the difference between your two warnings:
  • c could not be accesses
  • d is not a directory
when would you show one and not the other?
__________________
Mike
Reply With Quote
  #4 (permalink)  
Old 04-25-11, 11:05
ch28456 ch28456 is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
Quote:
Originally Posted by mike_bike_kite View Post
Also what is the difference between your two warnings:
  • c could not be accesses
  • d is not a directory
when would you show one and not the other?
Such as if a directory wasn't accessible due to permissions. And the other is if one or more of the files specified wasn't a directory
Reply With Quote
  #5 (permalink)  
Old 04-25-11, 11:13
ch28456 ch28456 is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
Quote:
Originally Posted by kitaman View Post
Seems to me it would be much simpler to use 'du'

Code:
du -s a b c d
Then add the 4 lines of output to get the grand total.
Thanks that probably would of been easier but
sorta new to the programming in unix so at least i got a chance to work it out. plus it's already written through sed to just give just the block outputs.
Reply With Quote
  #6 (permalink)  
Old 04-25-11, 14:31
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Instead of using test -e, use test -d to see if the input is the name of a directory rather than a file
Reply With Quote
Reply

Tags
blocks, programing, shell, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On