Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Run SQL Server Job from Command Line


Run SQL Server Job from Command Line

Author
Message
Bob Bridges-173967
Bob Bridges-173967
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 Visits: 350

Good afternoon,

I need to daisy chain a SQL Server job with an AS400 job (have the AS400 job kick off the SQL Server job). I've been told that this can be done but how do I do this? What connectivity do I need and more pressing right now, what is the command line syntax for such a job?

thanks,

Bob


Adam Angelini
Adam Angelini
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1204 Visits: 1177
use either osql or sqlcmd, depending on your version of SQL (2000 uses osql, 2005 is sqlcmd)

you can use that to run sp_startjob

so your command may look like this:
osql -E -SserverName -q"sp_start_job @job_name = 'job_name', @server_name = 'server_name'"
Bob Bridges-173967
Bob Bridges-173967
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 Visits: 350

Thanks Adam... I had to tweak it just a bit but it works. One further question... when I run this from a command prompt, after it starts, there is a message that the command "started successfully." Then the next line looks like this...

1>

If I press the enter key it simply adds a >2 below that.

Does this mean the system is waiting on something to get me back to a regular command prompt?

Thanks again,

Bob


Bob Bridges-173967
Bob Bridges-173967
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 Visits: 350

Adam, I figured it out... in your example change the small q to a captial Q

Thanks again, Bob


Bob Bridges-173967
Bob Bridges-173967
SSC Journeyman
SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)SSC Journeyman (92 reputation)

Group: General Forum Members
Points: 92 Visits: 350

I got this to work using the sa account but not when I run it with a SQL Server account. I gave rights to the SQL Server account to execute the stored procedure as well as the sp_start_job stored procedure.

Any ideas how I can get a generic SQL Server account to work?

Thanks,

Bob


vconlan
vconlan
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 10
I am trying to use the same command and I am having trouble getting it to work. I am running this:



RUNRMTCMD CMD('sqlcmd -U user -P password -S server name -Q "msdb.dbo.sp _start_job @job_name = ''FACT852: ProcessRetailSales'', @server_name = '' server''"') RMTLOCNAME('99.99.99.99' *IP) RMTUSER(user) RMTPWD(password)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search