7

I've been tasked with fixing a vendor's program that, under certain conditions, dumps gigs of junk files into a log directory. It ends up filling users' machines. My task is to figure out how to make it stop without any source code or additional running processes, and without making the program kasplode. In other words, I'm looking to use a feature of the file system to control the growth.

One idea I had was to make a hard link from that folder to NUL, as you might with /dev/null in the linux world. However, my attempts to use the mklink program to create a junction result in a message that says Local volumes are required to complete the operation.

Any ideas on how to complete the junction, or other ideas to solve the problem?

6
  • out of curiousity: what for do you need this?
    – akira
    May 25, 2010 at 13:10
  • Symlinks are not the same as shell shortcuts. Beware of the terminology. (FWIW, in the Unix world a hardlink to /dev/null is a rare sight; symlinks are much more common.) May 25, 2010 at 13:37
  • More information (though not that much) about the "NUL" for Windows: msdn.microsoft.com/en-us/library/aa939249.aspx
    – Gnoupi
    May 25, 2010 at 13:47
  • I've been tasked with fixing a vendor's program that, under certain conditions, dumps gigs of junk files into a log directory. It ends up filling users' machines. My task is to figure out how to make it stop without any source code, and without making the program kasplode. May 25, 2010 at 14:32
  • 2
    Will your vendor's program crash if you change the permission level to deny write access to that folder that it sores its junk files in?
    – Usta
    Jun 9, 2012 at 2:53

7 Answers 7

1

No. Hard links are only available inside NTFS, and the NUL file is not an NTFS file - it's the WIN32 name of the \.\Devices\NULL namespace object, but you can't create a hardlink to it.

You could create a soft-link (a shortcut) to the NUL file if you wanted to, but I can't really think why that would be a good idea.

1

I am just spit balling ideas here but:

If the problem program has command line switches maybe it can be turned off. I would ask the vendor first, assuming you can and haven't.

If the vendor program makes some kind of system event that windows reads, maybe you can make a script that deletes the junk folder (batch, cmd or powershell). If this is possible, remember to wait till the vendor program is done dumping.

Last resort is to set up a scheduled task to delete on windows logoff. This requires the client machines have enough space for the junk to live for the duration of the session.

If the clients are servers, thus no logoff, set it to run, say every 24 hours or how ever often this happens divided by 2. Divide by 2 is to reduce the chance of double junk so to speak..

1

If you can persuade the program to write its log files in the root of a drive letter, say, T:, try

subst T: NUL:

because then redirection to the bit bucket works, eg things like this work:

echo > T:\some_file

What won't work are reads from the fake T: drive, folder creation and file read access. Which sorta makes sense, but maybe your app relies on those.

0

Why not just write a script that removes any .log files that get written to the offending directory on a regular basis (or at the beginning/end of using the program)? Granted, it's a band-aid until you can get the company to fix their program.

Such as:

do {}
While (Get-ChildItem C:\problemfile).Count = 0)
Remove-Item "c:\problemfile\*.log"
Write-Host “Program log file cleaned successfully”

I'm brand new to PoSH so this script may not work, but I think the concept is sound.

1
  • 1
    Or the more compatible and arguably easier thing in batch: del <folderpath>\*.<extension>. Might want to test on a useless directory first.
    – Bob
    Mar 5, 2012 at 23:18
0

If you don't need the offending log file and the path/name is a known variable, try creating it as a read only file as root/privileged user to prevent it's creation.

Alternatively you could create a read only volume/partition or ramdisk of a limited size that you symlink to, to limit the size of the file.

If the program does require the log file to continue operation and 'kasplodes' when it can't write then you may need a programmatic solution such as log rotations if you've been unable to pipe to null.

0

You could create a separate Windows User to run the program (must be a password protected account) and then right click on the drive that the logs get written to and select properties. Then click on the Quota Tab and setup a disk space quota for that user. Finally hold shift and right click on the .exe file that starts the program and select run as different user, selecting the account you just created.

-1

If you prefer the hard link, then you'll have to go with

C:>mklink /h "C:\Program Files\MyNewHardlinkFolder" NUL

2
  • I doubt that would work; NUL is not a real file, and it doesn't have any links. May 25, 2010 at 13:37
  • Doesn't. "Local NTFS volumes are required to complete the operation." May 25, 2010 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .