Office 2011, Mac OS Lion, Excel creates temporary file on Windows server 2008, SMB share how to stop?

1

I have an issue with Mac's and a windows SMB share, when using Excel 2011.

If I open an excel document from the windows share it will create a "Ghost file" starting with ~$ then the full filename e.g ::

If I opened testdoc.xlsx a ghost file will be created called ~$testdoc.xlsx this is not a major issue as when the document is closed the file is removed.

This file becomes a problem when my users are working through the VPN and if they disconnect their VPN without closing the excell document the "Ghost" file is left behind and then anyone on a mac can only open the file read only until this ghost file is removed.

I have tried using the apple command ::

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

This stop's the macs writing resource forks and DS store files to the network files but does not stop this ghost file creation.

Does anyone know what these files are? How to stop them being created? Is it safe to stop them?

Kind regards

Kevin

Posted 2012-12-13T12:24:17.467

Reputation: 11

1I think those are the auto-backup files, if so, the only way to get rid of them would be disabling auto-backup. – terdon – 2012-12-13T12:44:03.193

Thanks for the comment, I disabled Auto backup but the file still remains, as soon as the document is opened it appears. – Kevin – 2012-12-13T13:34:33.273

Answers

0

The other thing that occurs to me, since it is not the backup, is that it is a lockfile whose function is to prevent other users writing to the file if it is already open for writing, which is not a bad idea.

Clearly, the best solution would be to make your users act responsibly but that, of course, is a lost cause :).

So, what I would do is run a little cronjob that would search for such files, check if the file in question is currently open, and if not, remove the lockfile. The problem is that the only way I know of to check whether a file is open is lsof which lists the processes that are currently accessing a given file. However, this will only work if run from the computer that is currently accessing the file, not from the server. If you run it on the server and your user has it open on her local machine it will not return any output.

Depending on your setup, you may be able to extend this by checking which user created the lockfile, and running the script on their machine instead. So, in the hope that it will be useful, here is the script that will remove lockfiles referring to files that are not open by any programs on the current machine:

#!/bin/bash
## Define the regular expression we will use
regex='(.*)~\$(.+)'

## Find all files that begin with "~\$*" in the directory
## specified on the command line, the lockfiles
find ${@} -name "~\$*" -print0 2>/dev/null | while IFS= read -r -d '' file; do

    if [[ $file =~ $regex ]]
    then
        ## Get the name of the file that created the lockfile
        realname=${BASH_REMATCH[1]}${BASH_REMATCH[2]};
        ## Check if the file is currently open
        isopen=`lsof "$realname" 2>/dev/null | wc -l`
        ## If the file is not open (by a program running on the
        ## same machine as this script, delete the lockfile
        if (( $isopen == 0))
        then
            echo "Deleting $file..."
            rm "$file"
        fi
    fi
done

terdon

Posted 2012-12-13T12:24:17.467

Reputation: 45 216