BookmarkSubscribeRSS Feed
Quartz | Level 8

Hello Friends 


Can any one help me with the command to kill bjobs.


Lets says  I want to kill all jobs that are 2 days older specific with the date,time and jobs that are running on different nodes.


I tried something like this bjobs -u all |grep "Oct  7" |grep  "Oct  6" | egrep "node1|node2|node3" | awk '{print "bkill"  $1}'


but looks like not working as expected....I want to kill all jobs specific to different date,time and executing node.


would appreciate for all your help


Thanks in Advance

Meteorite | Level 14
I don't think your script would work.
I would do this in two steps procedure
Step 1: Create a a text file that has the required job names or ID
Step 2:Create another script to read the text file and kill the jobs.
Quartz | Level 8

Thanks for your prompt response


Actually this would be time consuming manually doing, which am doing curretly.

am looking something with a single line command which can kill multiple jobs with different dates, time and executing nodes.

Super User

First of all, only the superuser can kill other user's jobs.

Next, this

grep "Oct  7" |grep  "Oct  6"| 

seems to be mutually exclusive, so there will be nothing left after the second pipe

Use the extended regular expression switch, and the pipe character (which does an OR in regex):

grep -E "Oct  7|Oct  6"
Quartz | Level 8

so how does it would look the complete command ?

Super User

I would use a two-step approach like @Sajid01 suggested.

Start by running the

bjobs -u all

from a FILENAME PIPE, and fetch the result into a SAS dataset. Then you can do all the logic in a SAS program, and finally write the sellected process numbers to a textfile. A periodic superuser job can then pick up the file and do the kills. Or you call the kill script with sudo from the SAS program.

Quartz | Level 8

That looks lengthy process, instead I can simply copy and paste id's on excel with filter and use bkill, but there is a single line command which does all what am requesting. I used to do it in previous company, but am not able to recollect it.


Its something like similar or may be below command


 bjobs -u all |grep -v "Oct  7" |grep -v  "Oct  6" | egrep "node1" | awk '{print "bkill"  $1}' > bkill.ksh


bjobs -u all |grep node1 |grep   "Oct  7" | awk '{print "bkill"  $1}' > bkill.ksh


ksh -x bkill.ksh



Super User

The two-step method lets me keep a record (in a dataset) of facts that led to the decision of killing. That makes the process maintainable and creates accountability.


What about this (you could replace the echo commands with the actual bkill command).


timeago='2 days ago'
bjobs -o "jobid submit_time" -u all -noheader | sed 's/ /'$'\t''/' | while IFS=$'\t' read -r jobid time
dtSec=$(date --date "$time" +'%s')
taSec=$(date --date "$timeago" +'%s')
if [ $dtSec -lt $taSec ] 
        echo "NOTE: Job $jobid was submitted over $timeago"
        echo "NOTE: You should run bkill $jobid"
Greg Wootton | Principal Systems Technical Support Engineer
Quartz | Level 8
Thank you
But am looking for the command not exactly 2 days before, jobs submitted before noon 1 day before all should be killed.
So there are multiple jobs with different dates and different times executing from different nodes
You can modify the variable "timeago" to any date and time you wish to specify. For example, "12:00 yesterday"
Greg Wootton | Principal Systems Technical Support Engineer

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

CLI in SAS Viya

Learn how to install the SAS Viya CLI and a few commands you may find useful in this video by SAS’ Darrell Barton.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 1 like
  • 4 in conversation