Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

xp_cmdshell Expand / Collapse
Author
Message
Posted Wednesday, December 12, 2007 1:39 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 5:03 AM
Points: 1,508, Visits: 2,160
I'm having a little trouble with xp_cmdshell...wonder if anyone can spot anything incredibly stupid I'm missing.

This pdfcombine program just combines the first 2 files into one .pdf file. If I run the script below, it prints out 'GOOD'. along with the value of @CMD. But the file never gets created. However if I open a command prompt window using the same security context as the sqlserveragent account, copy the output from the PRINT @CMD, and run it, it works.

Am I missing something obvious? I've tried various combinations of quotes, and have even tried a full UNC path. In all cases, running the command in the command line works, but stops working as soon as I'm in SQL server. But I can do something simple like SET @CMD = 'DIR D:\' and that works.

DECLARE @CMD VARCHAR(512)
DECLARE @RESULT INT

SET @CMD =
'D:\JPMorgan_IMPORT\pdfcombine.exe D:\431411406.PDF D:\431411408.PDF D:\COMBINED.PDF'

PRINT @CMD
EXECUTE @RESULT = master.dbo.xp_cmdshell @CMD

IF @RESULT = 0
PRINT 'GOOD'
ELSE
PRINT 'BAD'


Jason Shadonix
MCTS, SQL 2005
Post #432529
Posted Wednesday, December 12, 2007 2:13 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, May 6, 2014 5:51 AM
Points: 6,266, Visits: 2,028
What authentication method are you using to connect to SQL Server, Windows authentication or SQL Authentication?


* Noel
Post #432547
Posted Wednesday, December 12, 2007 2:18 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 5:03 AM
Points: 1,508, Visits: 2,160
noeld (12/12/2007)
What authentication method are you using to connect to SQL Server, Windows authentication or SQL Authentication?


Windows Authentication. The user is both a sysadmin, and a local admin on the server involved.


Jason Shadonix
MCTS, SQL 2005
Post #432548
Posted Wednesday, December 12, 2007 2:54 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 9:29 PM
Points: 2,644, Visits: 826
What service account is SQL Server running under? Make sure it has the necessary NTFS permissions to run the executable and write to the destination folder.





Scott Duncan

MARCUS. Why dost thou laugh? It fits not with this hour.
TITUS. Why, I have not another tear to shed;
--Titus Andronicus, William Shakespeare
Post #432568
Posted Wednesday, December 12, 2007 2:58 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 5:03 AM
Points: 1,508, Visits: 2,160
Scott Duncan (12/12/2007)
What service account is SQL Server running under? Make sure it has the necessary NTFS permissions to run the executable and write to the destination folder.



I don't think it's permissions. I logged onto the server as the user that the services are running under, and that's what I'm using to manually execute from the command prompt.

It's got to be something just silly I'm missing...


Jason Shadonix
MCTS, SQL 2005
Post #432569
Posted Wednesday, December 12, 2007 3:23 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 9:29 PM
Points: 2,644, Visits: 826
What happens if you try running:

master..xp_cmdshell 'D:\JPMorgan_IMPORT\pdfcombine.exe D:\431411406.PDF D:\431411408.PDF D:\COMBINED.PDF'

Are any error messages returned? Or is it just the never helpful 'NULL'





Scott Duncan

MARCUS. Why dost thou laugh? It fits not with this hour.
TITUS. Why, I have not another tear to shed;
--Titus Andronicus, William Shakespeare
Post #432582
Posted Thursday, December 13, 2007 4:27 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 9:52 AM
Points: 1,326, Visits: 1,288
Hi,
The code is good
Try just to execute in the command line
D:\JPMorgan_IMPORT\pdfcombine.exe D:\431411406.PDF D:\431411408.PDF D:\COMBINED.PDF to see if it works

Check the following link
http://www.coolutils.com/forum/read.php?f=1&i=914&t=914

Regards,
Ahmed
Post #432750
Posted Thursday, December 13, 2007 8:05 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 5:03 AM
Points: 1,508, Visits: 2,160
Ahmed Bouzamondo (12/13/2007)
Hi,
The code is good
Try just to execute in the command line
D:\JPMorgan_IMPORT\pdfcombine.exe D:\431411406.PDF D:\431411408.PDF D:\COMBINED.PDF to see if it works

Check the following link
http://www.coolutils.com/forum/read.php?f=1&i=914&t=914

Regards,
Ahmed


That's the strange thing. It works fine from the command line (when running with the same user the service accounts are running as).

I've even tried putting a bunch of those commands in a batch file, and just running the batch file from xp_cmdshell. It doesn't work. But if I run the batch file from the command line it works again.

Normally I would think it's a permission error, but since xp_cmdshell (at least according to books online) runs with the credentials of the sql server agent service account, and I can log on as that service account to the desktop and run it manually with sucess, I'm not sure it's security. I can do simple things like:
...
xp_cmdshell 'dir d:\'

And that works, so I also don't think it's any obvous configuration issue either.



Jason Shadonix
MCTS, SQL 2005
Post #432865
Posted Thursday, December 13, 2007 1:12 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 5:03 AM
Points: 1,508, Visits: 2,160
It's finally solved.

Our network guy who(m) is much more clever than me added an entry in the PATH variable and it magically started working. Apparently the pdfcombine program was having troulbe finding the license info.

One interesting that that was discovered:

Run the following: EXECUTE master.dbo.xp_cmdshell 'SET'
and then run SET from the command prompt. (make sure you are logged in as the account that the agent is running as). For me it's returning different things in the 'PATH' variable.


Jason Shadonix
MCTS, SQL 2005
Post #433052
Posted Thursday, December 13, 2007 1:14 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 9:52 AM
Points: 1,326, Visits: 1,288
Thanks Jason for sharing the info.

Regards,
Ahmed
Post #433053
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse