Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

xp_cmdshell Expand / Collapse
Author
Message
Posted Thursday, December 13, 2012 4:04 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:45 AM
Points: 37, Visits: 352
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
Post #1396102
Posted Thursday, December 13, 2012 4:08 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, November 1, 2014 6:54 AM
Points: 5,221, Visits: 5,118
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.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1396104
Posted Thursday, December 13, 2012 4:16 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:45 AM
Points: 37, Visits: 352
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.
Post #1396105
Posted Thursday, December 13, 2012 4:29 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 7:21 AM
Points: 1,159, Visits: 4,658
fhfh (12/13/2012)
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.


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

Helping SQL DBAs and Developers >>>SqlserverBlogForum
Post #1396113
Posted Thursday, December 13, 2012 4:31 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, November 20, 2014 8:00 AM
Points: 202, Visits: 392
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)

Post #1396114
Posted Thursday, December 13, 2012 4:40 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:45 AM
Points: 37, Visits: 352
Do you know what is the syntax of NET use in my scenario ?
Post #1396121
Posted Thursday, December 13, 2012 4:41 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 20, 2014 4:45 AM
Points: 37, Visits: 352
tried to map the network drive with username and password but no luck
Post #1396122
Posted Thursday, December 13, 2012 5:47 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, March 3, 2014 4:05 AM
Points: 47, Visits: 236
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/
Post #1396138
Posted Thursday, December 13, 2012 7:29 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 7:21 AM
Points: 1,159, Visits: 4,658
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

Helping SQL DBAs and Developers >>>SqlserverBlogForum
Post #1396186
Posted Thursday, December 13, 2012 8:27 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Today @ 5:32 AM
Points: 1,465, Visits: 2,767
anthony.green (12/13/2012)
You cannot use UNC paths in a CMD window.


Just for clarification, You can use UNC paths in a CMD windows. It is FORFILES that does not allow UNC paths.


Bob
-----------------------------------------------------------------------------
How to post to get the best help
Post #1396224
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse