ruby - Print job programming not cancelling -


i've created program scan through server specified user , output list of print jobs on server, there output jobs older 2016, , gsub down job id number.

then it's suppose cancel job, it's doing saying:

cancelling job: 829116 cancel: cancel-job failed: job #829116 not exist! cancelling job: 795259 cancel: cancel-job failed: job #795259 not exist! cancelling job: 795260 cancel: cancel-job failed: job #795260 not exist! cancelling job: 797216 cancel: cancel-job failed: job #797216 not exist! cancelling job: 797217 cancel: cancel-job failed: job #797217 not exist! 

when exist, if go specific server , run prt_jobs job pops up.. example:

#on server ran prt_jobs cdprt11-829116          dij             244736   mon aug 24 06:07:12 2015 closing_2-795259        dlc             228352   tue jul 28 13:43:08 2015 closing_2-795260        dlc             228352   tue jul 28 13:44:05 2015 closing_2-797216        tkb             286720   wed jul 29 13:56:27 2015 closing_2-797217        tkb             250880   wed jul 29 13:56:41 2015 

can tell me why it's not cancelling jobs specified?

source:

#!/usr/local/bin/ruby  require 'rubygems' require 'net/ssh' require 'etc'  class printjobs   host = argv[0]  username = etc.getlogin  password = nil   def scan_for_jobs    check_jobs = net::ssh.start(host, username, :password => password) |ssh|      cmd = "prt_jobs"      info = ssh.exec!(cmd)      if info == nil        puts "no print jobs on server #{host}"      else        res = info.split("\n").reject {|line| line.match(/\s+2016/s+/)}.join("\n")        puts res        print "process kill que: "        input = stdin.gets.chomp.upcase        if input == "yes"          kill_que(check_jobs, res)        else          exit 1        end      end    end  end   def kill_que(check_jobs, res)    puts "loading jobs kill que.."    column = 0    job_ids = res.lines.map { |job| job.split(/\s+/)[0] }.each |task_id|      kill_jobs(task_id)    end  end   def kill_jobs(task_id)     id_to_strip = task_id.gsub(/\-/," ")     column = 1     stripping_id = id_to_strip.lines.map { |task| task.split(/\s+/)[1] }.each |id|       id.strip       puts "cancelling job: #{id}"       `sudo cancel #{id}`       # puts id     end   end end  test = printjobs.new test.scan_for_jobs 

as pointed in comments question, cancel command issued on local server , not on remote server. need pass ssh object kill_jobs , execute command on ssh connection.

step 1: pass ssh kill_que method.

   if input == "yes"      kill_que(ssh, check_jobs, res)  # *** pass ssh object 

step 2: update kill_que method use ssh object

def kill_que(ssh, check_jobs, res)    puts "loading jobs kill que.."    column = 0    job_ids = res.lines.map { |job| job.split(/\s+/)[0] }.each |task_id|      kill_jobs(ssh, task_id)  # *** pass ssh kill_jobs    end end 

step 3: use ssh in kill_jobs

def kill_jobs(ssh, task_id)     id_to_strip = task_id.gsub(/\-/," ")     column = 1     stripping_id = id_to_strip.lines.map { |task| task.split(/\s+/)[1] }.each |id|       id.strip       puts "cancelling job: #{id}"       ssh.exec!("sudo cancel #{id}")  # *** issue command via ssh       # puts id     end end 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -