I want to have one log file for each task ran within a job. There are several tasks for each job that may be handled by different people so I would like to have a running log file on the network that can be checked by supervisors. I know how to creat the log file:
master..xp_cmdshell bcp "SELECT * FROM ##logFile" queryout "c:\log.txt"
Problem is next time a task is run, the original text file will get written over by the new one. I came up with a solution for that by using bcp to export a temporary log file, then append that file to my existing log file, then kill the temporary file and that works fine:
master..xp_cmdshell copy log_temp.txt + log.txt
The problem is the second command obviously fails if the main log file does not exist.
Ideally I would like to check to see if the log file exists, if not create it, if it does exist, append to it.
Having a master log table stored in SQL has been suggested and shot down. They want one text file for job ran.
Any help would be greatly appreciated.
Thanks.
Tim
Write VBScript code (for example) and run this in a SQLAgent job. Don't use xp_cmdshell for these sort of things. It is less flexible and a security vulnerability. It takes few lines of code in VBScript to check for file. Or you can write a CMD script and run it in a SQLAgent job.
没有评论:
发表评论