I am trying to execute a perl script from xp_cmdshell.
The output of the perl script is a csv file, but when I run
EXEC master..xp_cmdshell N'perl G:\script\perl.pl';
I can't find the csv file created, though the xp_cmdshell command seems to run fine, the output is the name of file that has to be created.
I am using xp_cmdshell to create a job step to execute the perl script.
Any help would be appreciated.
Since you're running this via a SQL Agent job, it'll be much safer to disable the use of xp_cmdshell via sp_configure (ref1 | ref2) and use a CmdExec job step instead.
When configuring the job step, be sure to go to the advanced page and enable job step logging to a table.
This will allow you to better troubleshoot the issues you're having with the perl job in general, as the issue could be related to something entirely outside the context of the database engine.
Related
I am trying to use the MPUT/MGET scripts as shown in:
https://www.codeproject.com/Articles/1170393/Download-file-s-from-FTP-Server-using-Command-thro
But i cant get it to work, is there a way to check if you have enought acces to be able to automate ftp through SQL ?
This script builds OS command and runs it using Sql Server xp_cmdshell system stored proc. To check current permission to run xp_cmdshell run
EXEC sp_configure;
without parameters and find the row with the name = 'xp_cmdshell'.
If you need to enable it see how to enable xp_cmdshell.
I want to run batch file from SQL Job without using exec xp_cmdshell.
Any idea?
Thanks
You could use a SQL Server Job, otherwise i cannot think of a way you could without xp_cmdshell.
Take a look at this
I want to run batch file from SQL Job without using exec xp_cmdshell.
Any idea?
Worth to mention that you can also leverage SQLCLR.
Example: CLR Stored procedure to execute command
Some other googlable threads:
How to execute a DOS command when xp_cmdshell is disabled in SQL Server
Executing an external process() in SQLCLR Project
Such approach introduces severe risks like memory leaks, crashing of underlying .net app pool etc
Therefore another link: Security in the CLR World Inside SQL Server
Instead of running batch file, i have created power shell and ran it from SQL job. It satisfy my requirement and resolved my issue.
Do it like the picture: like this image.
The drive containing the batch file should be other than the C drive, to avoid trouble.
Add execute, read and write permissions for the user, which you are using to run the batch file, to get the username run this query: EXEC master..xp_cmdshell 'whoami', get the name after the \ sign. For example "nt service\mssqlserver". Add permission for this user: mssqlserver
Finally make sure you put the batch file on the same server as where you execute your Job.
I was wondering if it is possible for SQL Server to check a directory for files and run a stored procedure. I did some research and found this, but I am wondering if there is a way to do what I want WITHOUT SSIS.
EDIT: After reading my post, I realized I should have been more specific. Is there a way to AUTOMATICALLY or set SQL Server to check for files in a directory and run a stored procedure?
You can use xp_cmdshell to run file related commands. To get a directly listing:
exec xp_cmdshell 'dir *.csv';
You can also use bulk insert to load a file from disk into a table and take actions based on the loaded contents.
Normally you'd use the File Watcher Task with SSIS. But you can also use SQL Server Agent to schedule a task for periodic execution, schedule a task with Windows Task Scheduler, or configure a stored procedure to runs at startup with sp_procoption that pauses (using waitfor) between processing times.
Can I define a Server Job as Oracle Database Procedure?
I will need to schedule running a database procedure using Siebel Server Jobs.
Thanks in Advance.
No you cannot do that. If you are asking something like triggers that is a separate thing.
There is currently no Direct Method to run a DB stored procedure. The common way of implementing this is through the command line and calling SQL Plus. In this tutorial it's explained in a step-by-step way. This will allow you to create a business service and use it in a workflow that can then be used to power a Siebel Job.
You can do this way on Unix servers:
1.Create a SQL script file on Siebel server(s) depending on your component definition on a particular server.
exec my_package.MY_STORED_PRC;
2.Call the file inside your BS:
Clib.system(“sqlplus $my_user/$my_password#dbname #//SBA_81/siebsrvr/bin/my_stored_proc_caller.sql”);
3.Define an RCR template, calling the BS/WF RunProcess:
4.Create RCR with scheduling time & start it.
You can also call the sql file inside a shell script file & invoke shell script file
Shell script file: my_shell_file.sh
sqlplus -S $my_username/$pwd#db_instance "#"my_stored_proc_caller.sql"
Give execute permission to the file.
Then execute it inside BS:
Clib.system(“/sieb/server/path/my_shell_file.sh")
Hi Please try this option by executing OOB BS "EAI ODBC Service" method "Execute Procedure". Hope it will help you
I am not allowed to use command prompt, unfortunately.
Currently I use SQL Server Management Studio, but I could switch to VS2010, if it was easier there.
Running a set of scripts in a specific order, especially when doen manually, is a bit tedious.
Thank you very much for any suggestions you might have.
You can edit and run SQL scripts in SSMS if this helps
You can use :r filename.sql command in the SQLCMD script command to execute a sql script
:r first.sql
:r second.sql
One method would be to create a job with no schedule, then you can run it manually.
Each step in the job could be one of your scripts.
The benefit of using a job would be that you could set up alerting and get an email if any step failed.