0

I am trying to call a bash command through a user account with PsExec. Cygwin is being used, and I am trying to run a command from SQL:

exec master..xp_cmdshell 'psexec -u cyg_server -p <pwd> -accepteula "bash script.sh"';

However, I get the following error from psexec:

Access is denied.

PsExec could not start bash script.sh:

Any suggestions?

I am using SQL 2005, Windows Server 2008, and Cygwin with fresh binaries

Eric
  • 92,005
  • 12
  • 114
  • 115
ccook
  • 5,869
  • 6
  • 56
  • 81
  • Do you have the appropriate db permissions to access the command shell in sql server? – Russ Cam Jul 26 '09 at 23:21
  • yes, I get some output from PsExec before it fails. The same command works from cmd.exe. Here are the results from trying to run notepad from SQL "PsExec v1.96 - Execute processes remotely Copyright (C) 2001-2009 Mark Russinovich Sysinternals - www.sysinternals.com NULL Access is denied. PsExec could not start notepad:" – ccook Jul 26 '09 at 23:26

1 Answers1

1

You're probably running this as a SQL user or a user without permissions to that file. My best bet is a SQL user (such as sa). When you do this, the Windows credentials it uses are of the Service Account, which is SYSTEM by default, but could be something else if you set it that way.

If you're just calling this from within SQL, make sure that you are, in fact, running as a Windows user that has permissions to open all of the files necessary.

If this is running in a SQL Server Agent job, you'll need to set up a Credential, and then set up a Proxy. Once you've done that, you can assign the Proxy to run the job (it's the third or fourth drop down on the Job Step dialog), and it will run with the correct Windows credentials.

Eric
  • 92,005
  • 12
  • 114
  • 115