December 13, 2012 at 4:04 am
Hello there,
i would like to delete all the files in a directory in another server using xp_cmdshell
EXEC xp_cmdshell 'FORFILES /p \\t-fc-fim\logs /m *.* /d -30 /c "CMD /C del /Q /F @FILE"'
i get an error ERROR: UNC paths (\\machine\share) are not supported.
what can i do to make this work ?
your help is much appreciated.
Thank you
December 13, 2012 at 4:08 am
You cannot use UNC paths in a CMD window.
Try mapping the UNC path as a mapped drive or use SSIS with a file system task.
December 13, 2012 at 4:16 am
I mapped the network drive in sql sevrer box and i have ran this
EXEC xp_cmdshell 'FORFILES /p I:\ /m *.* /d -30 /c "CMD /C del /Q /F @FILE"'
ERROR: The specified directory does not exist.:w00t:
December 13, 2012 at 4:29 am
fhfh (12/13/2012)
I mapped the network drive in sql sevrer box and i have ran thisEXEC xp_cmdshell 'FORFILES /p I:\ /m *.* /d -30 /c "CMD /C del /Q /F @FILE"'
ERROR: The specified directory does not exist.:w00t:
I hope you might know the risk about cmdshell. You can use the 'Net use with uname and password' to access the share.
Muthukkumaran Kaliyamoorthy
https://www.sqlserverblogforum.com/
December 13, 2012 at 4:31 am
sounds user profile related, are you mapping it as a persistent mapping with the same account as the sql-server is running (I'm not sure this will work, but it might)
December 13, 2012 at 4:40 am
Do you know what is the syntax of NET use in my scenario ?
December 13, 2012 at 4:41 am
tried to map the network drive with username and password but no luck
December 13, 2012 at 5:47 am
hi,
please refer below link, it will help u.
http://www.howtogeek.com/118452/how-to-map-network-drives-from-the-command-prompt-in-windows/
December 13, 2012 at 7:29 am
fhfh (12/13/2012)
Do you know what is the syntax of NET use in my scenario ?
http://www.sqlservercentral.com/Forums/Topic667056-145-1.aspx#bm1027279
Muthukkumaran Kaliyamoorthy
https://www.sqlserverblogforum.com/
December 13, 2012 at 8:27 am
December 13, 2012 at 9:11 am
Never tried FORFILES but this works well and is very simplistic EXEC MASTER.dbo.xp_cmdshell 'del \\YourUNCPath\*.*'
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
December 13, 2012 at 11:27 am
if this is something to be scheduled you could avoid xp_cmdshell and run this powershell script with SQL Agent.
$Now = Get-Date
$Days = “30”
$TargetFolder = “\\t-fc-fim\logs”
$LastWrite = $Now.AddDays(-$days)
get-childitem $TargetFolder *.* | Where {$_.LastWriteTime -le “$LastWrite”} |Remove-Item
you will have to make sure that the account that SQL Agent is running under has modify permissions the the shared folder.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply