Deleting scheduled jobs

Posts: 463
2095     0

This script uses the NetMRI perl API to delete any scheduled jobs in a NetMRI system. This can be useful if a script accidentally creates a lot of jobs. 

Warning: this will delete all of your scheduled jobs, including any you want to keep. If you run it, you'll need to recreate those jobs. Use with care. 



use warnings;
use NetMRI::API;
use JSON;
# Connect to the NetMRI API
  # Configure .netmri.yml with your
  # url: http://netmri
  # username: admin
  # password: secret
my $client = new NetMRI::API({ api_version => '2.7' });

# You can comment this out if you are only using HTTP

# Run the following “curl"command on either a MAC or Linux box(I'm not sure about Windows Machine) at the command prompt this will give you all the
# "Scheduled Jobs" ids so we are remove them using $broker->destroy
# curl -k --user "username:password" "https://netmri_ip/api/2.7/job_specifications/index?select=id&limit=10000" > job.txt;
my $filename = 'job.txt';
# We will read the file in to a variable call "$json_text"
my $json_text = do {
   open(my $json_fh, "<:encoding(UTF-8)", $filename)
      or die("Can't open ".$filename.": $!\n");
   local $/;

my $json = JSON->new;

# This will allow us to read the JSON file in PERL
my $data = $json->decode($json_text);

my $broker = $client->broker->job_specification;
print "Removing all the scheduled jobs...\n";
# We are going to remove all the Jobs in the "Scheduled Jobs"
for my $f ( @{$data->{job_specifications}} ) {
   $broker->destroy({id => $f->{id}});
   print $f->{id};
   print "\n";
print "Done.";
Follow me on LinkedIn:

Is there a reason you use the

Posts: 353
2096     0

Is there a reason you use the curl command rather than just calling $broker->index( { select => "id", limit => 10000 } ) ?

This was quick and dirty.  I

Posts: 463
2096     0

This was quick and dirty.  I will modify the script to use what you posted above, I will update the above script to post use NetMRI Easy as well.

Follow me on LinkedIn:
Showing results for 
Search instead for 
Did you mean: 

Recommended for You