Script to show diskspace?

I have modified the following script to show how much the home folder is using:

WindowTitle {FvwmApplet-splinux}
WindowSize  68 24     # Taille
Font		"Shadow=1:xft:Verdana:bold:pixelsize=12:minspace=true"
Init
 Begin
  Set $sp = Res: (GetOutput {exec du -h -s ~| awk '{print $1}'} 1 -1)
  ChangeTitle 1 $sp
End

PeriodicTasks
 Begin
  If (RemainderOfDiv (GetTime) 5)==0 Then
  Begin
    Set $sp = Res: (GetOutput {exec du -h -s ~| awk '{print $1}'} 1 -1)
    ChangeTitle 1 $sp
  End
End

Widget 1
Property
 Size 68 24
 Position 0 0
 Colorset 60
 Font		"Shadow=1:xft:Verdana:pixelsize=11:minspace=true"
 Flags Left
 Type ItemDraw
 Title {}
End

Originally the script used the ‘read’ command but the system that I am running this script on does not have that command.

But the above script does not output anything, any hints to what I am doing wrong?

Keeping this in your original thread would have been nice/

It’s not a command, it’s a shell builtin that’s in all sh and bash shells. What makes you think you don’t have it?

Yes, you’re quoting sucks.

– Thomas Adam

I get the error command not found if I type read. It only works if I first type sh or bash.

What do mean by my quoting sucks?

Of course it does. It’s part of the shell. So enclose the whole thing in sh -c ‘…’

– Thomas Adam

What is was looking for was this:

sh -c 'exec du -h -s ~ | ( read y x ; echo " $y" )'

Uh huh, although the use of the ‘exec’ is completely unnecessary.

– Thomas Adam

Btw is there someway to subtract the result from a number. Lets say that the result is 30 M and I have 40 M capacity then I would like to subtract y from 40 before printing the result.

thought of something like:

sh -c 'du -h -s ~ | ( read 40 -y x ; echo " $y" )'

but it seems that its no as simple. Is even possible?

There is, and this now just becomes shell-mechanics. So, assuming you know the capacity overall you can do:

cap=40

Then in your script:

sh -c 'cap=40; du -s /somewhere | (read x y; echo " $((cap - x))")'

Of course, ascertaining the value of the overall capacity can be done with ‘df’ if you wish – assuming the directory being df’d was a partition, and existed on one (that you could ascertain).

– Thomas Adam

I assume you mean ‘cap - y’ and not ‘cap - x’. But I get this error:

appo ~ > sh -c 'cap=40; du -h -s ~ | (read y x; echo "$((cap - y))")'
sh: line 1: 27M: value too great for base (error token is "27M")
appo ~ > 

No, I really meant “x” – that’s the numerical part of the output (look at the example in my last post. It’s not consistent with your variable assignage, but hey – I am sure even you have the notion enough to transpose them.)

Look again at my example. “-h” is only ever useful when you’re dealing with humans (hence the reason it’s “human-readable”.) Omit the ‘-h’ flag, and you’ll get the raw number (again, as per my example).

– Thomas Adam

I don’t think so, here ‘x’ is the path:

appo ~ > sh -c 'cap=41; du -s ~ | (read y x; echo "$x")'
/home/disk10/fuzz

and here ‘y’ is the number:

appo ~ > sh -c 'cap=41; du -s ~ | (read y x; echo "$y")' 26904 appo ~ > sh -c 'cap=41; du -s ~ | (read y x; echo "$(cap-y)")' []

and now it seems to work:

appo ~ > sh -c 'cap=41; du -s ~ | (read y x; echo "$((cap-y))")'
-26831
app-2 ~ > 

now it a matter of finding out how much 41 MB is in ‘inhuman’ mode and then convert the difference to ‘human’ mode.

Uh huh, and if you look at my original example, all I did was swap them around, subconsciously:

No big deal – I thought you might have been able to have realised that and substituted them as appropriate. I was wrong, you can’t even do that.

Simple mathematics, for which I am not even going to dignify with an answer.

– Thomas Adam