SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


xp_cmdshell


xp_cmdshell

Author
Message
zouzou
zouzou
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1322 Visits: 614
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
anthony.green
anthony.green
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62652 Visits: 8597
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.



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
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


zouzou
zouzou
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1322 Visits: 614
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
muthukkumaran Kaliyamoorthy
muthukkumaran Kaliyamoorthy
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10435 Visits: 4997
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.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

Helping SQL DBAs and Developers >>>SqlserverBlogForum

Illwill
Illwill
Old Hand
Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)

Group: General Forum Members
Points: 384 Visits: 430
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)
zouzou
zouzou
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1322 Visits: 614
Do you know what is the syntax of NET use in my scenario ?
zouzou
zouzou
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1322 Visits: 614
tried to map the network drive with username and password but no luck
Hemant.R
Hemant.R
SSC Eights!
SSC Eights! (864 reputation)SSC Eights! (864 reputation)SSC Eights! (864 reputation)SSC Eights! (864 reputation)SSC Eights! (864 reputation)SSC Eights! (864 reputation)SSC Eights! (864 reputation)SSC Eights! (864 reputation)

Group: General Forum Members
Points: 864 Visits: 240
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/
muthukkumaran Kaliyamoorthy
muthukkumaran Kaliyamoorthy
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10435 Visits: 4997
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

Robert klimes
Robert klimes
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11069 Visits: 3493
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search