Can a job be scheduled to run a Win2000 batch file | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Can a job be scheduled to run a Win2000 batch file

I created a batch file that I would like to run daily from SQL Server. The file is located in a directory on the server and needs to be executed from there. Can I create a job and run this bat file? If the file was called file.bat, how would I create the step that would go out and run it?
Yes, this will work, as long as the user who owns the account can access the local drive and the bat file to be executed. —————————–
Brad M. McGehee, MVP
Webmaster
SQL-Server-Performance.Com
You can use XP_CMDSHELL to run the batch files to add as a job step, provided Brad’s tip is satisfied. Satya SKJ
Moderator
http://www.SQL-Server-Performance.Com/forum
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
When I do this… declare @command varchar(50) set @command = ‘f:ackupslogapp.bat’ exec master..xp_cmdshell @command It doesn’t recognize the drive. Why?
Is F: a local drive on the server ? Does the SQL Server service startup account have access to this drive and the folder ? Try running xp_cmdshell ‘Dir f:’ and see if you can get the directory listing. Here’s an excerpt from BOL : When xp_cmdshell is invoked by a user who is a member of the sysadmin fixed server role, xp_cmdshell will be executed under the security context in which the SQL Server service is running. When the user is not a member of the sysadmin group, xp_cmdshell will impersonate the SQL Server Agent proxy account, which is specified using xp_sqlagent_proxy_account. If the proxy account is not available, xp_cmdshell will fail.
It doesn’t recognize the drive. Why?
Any error or information with this execution> Satya SKJ
Moderator
http://www.SQL-Server-Performance.Com/forum
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
if the drive is a mapped drive and not local you can use xp_cmdshell to call it from a unc path. you will need a share and security access to the share. exec xp_cmdshell ‘\servernamesharefile.bat’ as long as windows can ping on browse by hostname. you could even do it via ip. exec xp_cmdshell ‘\10.10.10.1sharefile.bat’ detroit
I believe F: would be local drive and ensure the SQL service account does have required privilege to access it. Satya SKJ
Moderator
http://www.SQL-Server-Performance.Com/forum
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
]]>