on ‎2023 Feb 21 3:03 PM
I would like to abort a job from the command line by sending a command to the Data Services Management Console to simulate a user clicking the Abort button for a job. I know that I can find the PID and kill the associated al_engine job but I currently don't have access to the job server so I'm looking for an alternate way to programmatically kill a batch job that doesn't involve executing a command on the job server.
If there is a way to do this, please let me know, thanks!
Dave Christy
Request clarification before answering.
Hi David,
You can use web services with Stop_Batch_Job operation, I think this should help. Please check the data integrator guide.
Thanks
Nawfal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Nawfal, I'll work on implementing this!
Greetings sapuserapr2021y,
The Simplest and quick solution to abort the job using the process id is to use the exec() function to send a kill signal This does not require one to have access to the Job server. For example:
If your Job server is on windows you can kill the process as shown below.
# this will send a ungraceful kill command to the process with PID 11344
# For graceful shutdown just remove the /F flag and the process will be aborted gracefully.
print(exec('powershell.exe','taskkill.exe /F /PID 11344'));If your job server is on Linux you can kill the process as shown below
# this will send a ungraceful kill command to the process with PID 28083
print(exec('kill', ' -9 28083 ',8));Best Regards,
Joseph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Greetings sapuserapr2021,
There is no function to retrieve the PID unfortunately. My approach to this would to create a custom function that reads a job's trace logs and retrieves the process ID.

I would then try to make the function more dynamic such that you can retrieve the process id of any job so long as the job is running. This means that functions such as get_trace_filename() and job_run_id() are out of the equation. This only leaves getting the trace log from the AL_HISTORY & AL_HISTORY_INFO tables. The query would look like below which you can call from the designer using sql() function.
SELECT ah.OBJECT_KEY,ah.SERVICE,ahi.VALUE
FROM AL_HISTORY ah INNER JOIN AL_HISTORY_INFO ahi
ON ah.OBJECT_KEY = ahi.OBJECT_KEY
WHERE ahi.NAME = 'TRACE_LOG_INFO'
AND ah.SERVICE='JB_HANA' -- make the job name here a parameter
AND END_TIME IS NULL -- End time is null meaning the job is still running or got terminated prematurely
ORDER BY ah.OBJECT_KEY DESC
LIMIT 1;
# From the designer call the sql function like
sql('REPO', 'SELECT ahi.VALUE FROM AL_HISTORY ah INNER JOIN AL_HISTORY_INFO ahi ON ah.OBJECT_KEY = ahi.OBJECT_KEY WHERE ahi.NAME = \'TRACE_LOG_INFO\' AND ah.SERVICE='[$JOB_NAME]' AND END_TIME IS NULL ORDER BY ah.OBJECT_KEY DESC LIMIT 1;');Once you have retrieved the trace log using the above query you can then read the first entry in the log file to retrieve the process id. and then using the exec function you can kill the job. One downside with this is that you would need to register the repository as a data store.
I would then make it shareable via the central repository for use by other developers as well.
This is just my train of thought, i haven't tested this, but this is just how i would approach it.
Best regards,
Joseph
Thank you for your help Joseph. I put together a small powershell script that will find the pid when given the path to the trace log:
$line1 = Get-Content "<path to the trace file>" -First 1
# get the 4th token
$token4 = $line1.split(' ')[3]
# remove parentheses
$token = $token4 -replace '[()]',''
# get the pid and taskid
$procid = $token.split(':')[0]
$taskid = $token.split(':')[1]
# check to see if it's running and if so, kill it
if (Get-Process -ID $procid -ErrorAction SilentlyContinue)
{ Write-Output "Process is running" taskkill.exe /F /PID $procid}
else { Write-Output "Process is NOT running"}
Thanks again for your help!
Dave
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.