Test for existence of file on remote system

Hi,

I’m trying to create a fixlet that tests for the existence of several files on a remote system, and if any of those files exists, delete the file(s) that are found.

Here is an example of the code I have (Setting up the values):

parameter "RemoteSystem" = "host.domain.name"
parameter "RemoteShareName" = "Share$\folder"
parameter "ready_tag" = "\\{parameter "RemoteSystem"}\{parameter "RemoteShareName"}\ready.txt"

and then referencing the values in if statements

if {exists file "(parameter "ready_tag")"}
   exit 91
endif

The fixlet fails on the line with the if statement on it.

Any ideas why this is failing?

Thanks,
Bob_K

In this line, you’re already inside of a relevance substitution, so adding quotes would start a literal string. Syntactically that’s broken because it treats the string from the first doublequote to the second - i.e. "(parameter " is the string, and then ready_tag is interpreted as a Relevance statement but it’s not a valid command.

If this were going to work, you’d need to use

if {exists file (parameter "ready_tag")}

However that’s unlikely to be successful either, because the LocalSystem account on one computer is not going to be able to connect to the network share of another computer, unless you have taken some serious effort to reduce the security configuration of the target server.

Why not run this on the server hosting the share instead? Otherwise you’re going to need to do something to pass username/password credentials to the share server

1 Like

@JasonWalker,

Thanks.

Why not run this on the server hosting the share instead?

Because the remote server is the DR Root Server…

I resorted to embedding some powershell code that was able to deal with the network share. (I know, the else isn’t necessary in the code, but I put it there anyways…

createfile until _PS_
 
#Files Array
$Files = "{parameter "ready_tag"}", "{parameter "archive_ready_tag"}", "{parameter "working_tag"}", "{parameter "complete_tag"}", "{parameter "replication_active_tag"}", "{parameter "replication_helper_active_tag"}"
 
Initialize Error Code variables
$ErrorCd = 0    #Start with no error
$ErrorBit = 1   #Bit to show which files exist (1 2 4 8 16 32)
 
#Check Files exist
ForEach ($File in $Files) {
    # Test if file exists
	If (Test-Path $File -PathType Leaf) {
	    $ErrorCd = $ErrorCd + $ErrorBit
	} Else {
		$ErrorCd = $ErrorCd
	}
	$ErrorBit = 2 * $ErrorBit
}
 
exit $ErrorCd
 
_PS_

move __createfile check_file_exists.ps1

waithidden powershell -F check_file_exists.ps1

Thanks,
Bob_K