-1

Hello I have a windows 10 computer and am using Git Bash version 2.23.0. I am trying to learn how to write basic scripts following an online tutorial. The goal of this code would be to write the output to a different file as an html file. However the problem is that my 'du -s ~/../*' command never actually finishes.

#!/bin/bash
# This is an example

home_space()
{
   cat <<- _EOF_
   <h2>Space usage per user</h2>
   <pre>$(du -s ~/../*)</pre>
   _EOF_
}

cat <<- _EOF_
<html>
<head>
   <title>Blah</title>
</head>

<body>
   $(home_space)
</body>

</html>
_EOF_

Expected output file:

<html>
<head>
   <title>Blah</title>
</head>

<body>
   <h2>Space usage per user</h2>
<pre>0   /c/Users/me/../All Users
2714     /c/Users/me/../Default
0        /c/Users/me/../Default User
1        /c/Users/me/../desktop.ini</pre>
</body>

</html>

Instead it runs forever. When I try it on the command line the output is what I expect it to be but the shell prompt never returns unless I do a keyboard interrupt with CTRL-C.

My work around was just to use the timeout function, but I am curious why the du command doesn't just terminate on its own, and whether something is wrong?

1 Answers1

1

From the OP, looks like the 'du' never finish, even when executed from the command line.

Consider one of two tools to troubleshoot:

  • Use 'du -a ...', instead of plain 'du'. It will show output per file, making it easier to identify where does the process hangs
  • Use 'strace du ...', which will show you trace of system calls. making it easier to tell if the process is hanging, or just processing lot of data.

Most likely, you have a large folder that take forever to complete. On my machine, running 'du' on a tree with "Eclipse" installed, takes practically forever.

dash-o
  • 13,723
  • 1
  • 10
  • 37