Need a UNIX expert to create a new UNIX command

Need a UNIX expert to create a new UNIX command

Post by Jocelyn Burg » Wed, 07 Jun 2000 04:00:00



I do not know if it is the right place to post this article
but it's the only one I found.

I like to create my "own" UNIX command similar to the command: du
I do not want to create an alias.

I'd like to create a command, let's call it "diskfull", that does
exactly the same thing as du but the output will be in my own format.

Example:

[nautilus:jxb] 11% diskfull -M filename
Result: The reported occupied space is in Mbytes

OR

[nautilus:jxb] 11% diskfull -G filename
Result: The reported occupied space is in Gbytes

The way I see it the only operation to do is

(Output from du -k)*512/1E6
OR
(Output from du -k)*1024/1E9

Does anyone have an idea on how to do that?

Thanks

Regards
JB

 
 
 

Need a UNIX expert to create a new UNIX command

Post by Andrew Mo » Thu, 08 Jun 2000 04:00:00




Quote:> I'd like to create a command, let's call it "diskfull", that does
> exactly the same thing as du but the output will be in my own format.

> Example:

> [nautilus:jxb] 11% diskfull -M filename
> Result: The reported occupied space is in Mbytes

> OR

> [nautilus:jxb] 11% diskfull -G filename
> Result: The reported occupied space is in Gbytes

How about something like:

#!/bin/sh
if [ "$1" = "-M" ]
then
  du -k $2 | awk '{print ($1 / 1024) " " $2}'
else
  du -k $2 | awk '{print ($1 / 1048576) " " $2}'
fi

or something along those lines...

Cheers,

Andrew
--

         Unix Environment Specialist, Information Technology Services
                    La Trobe University, Bundoora

 
 
 

Need a UNIX expert to create a new UNIX command

Post by Joerg Brueh » Thu, 08 Jun 2000 04:00:00


Hi Jocelyn !


> I do not know if it is the right place to post this article
> but it's the only one I found.

Not quite, IMHO - your desire is not specific to Tru64.
However, I do not know an international group on Unix programming,
only the German one, so let us stay here (if nobody complains).

Quote:

> [...]

> I'd like to create a command, let's call it "diskfull", that does
> exactly the same thing as du but the output will be in my own format.

> Example:

> [nautilus:jxb] 11% diskfull -M filename
> Result: The reported occupied space is in Mbytes

> OR

> [nautilus:jxb] 11% diskfull -G filename
> Result: The reported occupied space is in Gbytes

> The way I see it the only operation to do is

> (Output from du -k)*512/1E6
> OR
> (Output from du -k)*1024/1E9

> Does anyone have an idea on how to do that?

Your approach of using standard 'du' and post-process the output would
work, but I propose something different:

Get the source for the GNU version of 'du' (from
   http://www.gnu.ai.mit.edu   or
   http://www.gnu.org/order/ftp.html )
and modify the output routine so that some argument like your '-M' or
'-G' will let the program do the conversion.
I do not know the size unit in which GNU's 'du' operates, but it might
use the traditional 512 byte blocks by default and switch to 1 kB by
an option '-k' (that is how AIX 'du' does/did it). In that case, you
would already find the proper place for your modification: look how
they handle '-k' and add your option(s).

If you feel there might be other users interested as well, you might
feed back your modification to the GNU maintainers.

Regards, Joerg Bruehe

--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
     (speaking only for himself)

 
 
 

1. Need to convert DOS to UNIX with a *limited* set of UNIX commands

I'm stuck! Need to do a text replace in files to convert them from DOS
into equivalent UNIX format (i.e. get rid of all the ^M characters).
But am using a system that has a BusyBox UNIX implementation on it that
supports a very limited set of unix commands. These are:

alias break builtin cd chdir continue eval exec exit export
false fc hash help jobs let local pwd read readonly return set
setvar shift times trap true type ulimit umask unalias unset
wait [ ash basename busybox cat chmod cp cut df dmesg du echo
env false find free freeramdisk halt hostid hostname init kill
killall ln logger ls mkdir mknod mktemp more mount mv nc nslookup
ps pwd reboot rm rmdir sh sleep sync test tftp touch traceroute
true umount uname uniq uptime

Can anyone see a way to do it from the command line automatically with
these commands? I'm aware that I could do it in Vi (which is also
available but not listed) but need it to be done at the command line
automatically as part of a script rather than as a manual process. Just
in case anyone suggests it, the system doesn't have any implementation
of SED, EMACS or TR.

Any advice on this would be much appreciated!

Cheers,
Steve

2. setsockopt(SOL_SOCKET, SO_SNDBUF) broken on 2.4.18?

3. Creating a new Unix/Linux shell - Help needed...

4. Ye ol' HP Deskwriter and MkLinux

5. NEED CHICAGO AREA UNIX/PERL EXPERT

6. linux users in Carmel, CA

7. EXPERT UNIX INTERNALS/NETWORK PROGRAMMERS NEEDED - Bluestone, Inc.

8. P6 / Pentium Pro & SCO

9. I need some expert Unix shell advice...

10. help?.need UNIX expert to solve this problem

11. East Coast Unix SP2 Expert Needed

12. SCO Unix Expert Needed

13. EXPERT UNIX INTERNALS/NETWORK PROGRAMMERS NEEDED - Bluestone, Inc.