?
Solved

xp_cmdshell copy file and append date to name

Posted on 2003-10-28
6
Medium Priority
?
2,017 Views
Last Modified: 2007-12-19
I am trying to copy a file and append the date to the name - I do not want the time, date only - using the xp_cmdshell (unless there is a better way) - I cannot get the date concatentaion for the life of me?

declare @rc int, @varDate sysname
SET @varDate = getdate()
exec @rc = master..xp_cmdshell 'copy c:\test\test_error_log.txt c:\test\test_error_log_"+@varDate+".txt', no_output
select @rc
0
Comment
Question by:tbaseflug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 9636178
Too many Open questions.
0
 

Author Comment

by:tbaseflug
ID: 9636184
I know - I am making the effort today to go and close some of them out - have been out of town for the past few months and have not had chance for cleanup
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 9636232
In that case, maybe try something like this:


declare @rc int
DECLARE @cmd VARCHAR(500)
SET @cmd = 'copy c:\test\test_error_log.txt c:\test\test_error_log_' +
      CONVERT(CHAR(8), GETDATE(), 112) + '.txt'
exec @rc = master..xp_cmdshell @cmd, NO_OUTPUT
select @rc

This will put the date in YYYYMMDD format; if you need another format, just let me know :-)
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:tbaseflug
ID: 9636245
wow - works great!  How would I format the date to something like:
mm_dd_yy
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 9636317
REPLACE(CONVERT(CHAR(8), GETDATE(), 1), '/', '_')
0
 

Author Comment

by:tbaseflug
ID: 9636342
Awesome!  Thanks!!!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question