On Monday 13 January 2014 16:44:45 Vladimir Skubriev wrote: > I need to know: "How I can list running jobs on client?" > > I want all runing jobs. > > I need this to determine is there are runing jobs already on the server. > > Or maybe status of my last restore job. But for example I don't remeber > jobID. > Thank you
Vladimir This may be overkill for what you want, but I have this very useful script that I use for many jobs like that. I've set up a number of symlinks for each of the different modes, so I can do something like: bgrep <clientname> Gary #!/usr/bin/perl -w use strict; my $prog=$0; $prog=~s|^.*/||g; my $format=''; # default to bconsole format my %formats=('s'=>'std','i'=>'id','d'=>'delim','n'=>'none'); my %options=('incRng'=>0,'incWtg'=>0,'format'=>'','execute'=>'','mode'=>''); use Getopt::Long; my $resp=GetOptions(\%options,"incRng|rng+","incWtg| wtg+","totals+",'r+','w+','j+','cancel+', "host|h=s","grep=s","exclude=s","mode=s","format=s", "usage|help|?|version",'debug+'); &help() if $options{usage}; $options{execute}='bacula_cancel !i' if $options{cancel}; $options{mode}='bjobs' if $options{mode} eq 'jobs' || $options{j}; $options{mode}='rng' if !$options{mode} && $options{r}; $options{mode}='wtg' if !$options{mode} && $options{w}; $options{mode}='bjobs' if $options{mode} eq 'jobs' || $options{j}; $options{mode}='bjobs' if $options{mode} eq 'jobs' || $options{j}; $options{mode}='bgrep' if $options{mode} eq 'grep'; $options{mode}='bgrep' if !$options{mode} && $options{grep}; $options{mode}='bjobs' if !$options{mode} && $options{host}; $options{mode}=$prog unless $options{mode}; $options{grep}=$ARGV[0]if ($prog eq 'bgrep' && !$options{grep} && $ARGV[0]); $options{format}=($options{execute}) ? 'none' : 'std' unless $options{format}; $options{format}=$formats{$options{format}} if $formats{$options{format}}; print "mode='$options{mode} format=$options{format} -execute='$options{execute}\n" if $options{debug}; die "No grep argument has been supplied" if $options{mode} eq 'bgrep' && ! $options{grep}; if ($options{mode} eq 'rng') { $options{incRng}++;} elsif ($options{mode} eq 'wtg') { $options{incWtg}++;} elsif ($options{mode} eq 'bjobs') { $options{incRng}++; $options{incWtg}++;} elsif ($options{mode} eq 'summary') { $options{totals}++;} elsif ($options{mode} eq 'bgrep') { } else { die "Invalid mode '$options{mode}'\n";} die "Invalid format $options{format}" unless ($options{format}=~/^(std|delim| id|none)$/); my @lines=`echo status dir|bconsole`; shift @lines while (@lines && $lines[0]!~/Running Jobs/); shift @lines; # 'Running Jobs:' shift @lines; # 'Console connected at 17-Dec-13 10:40' shift @lines; # ' JobId Level Name Status' shift @lines; # '======================================================================' my %counts=('rng'=>0,'wtg'=>0); foreach (@lines) { chomp; last if /^$/ || /^====$/; print "****'$_'\n" if $options{debug}; my $state='rng'; if (/waiting for (higher|its start time)/) { $state='wtg'} # This code excludes things like elsif (/waiting/i && $_!~/waiting for/) { $state='wtg'}; # waiting for storage device (running job) $counts{$state}++; print "state='$state'\n" if $options{debug}; my $print=0; $print=1 if $options{incRng} && $state eq'rng'; $print=1 if $options{incWtg} && $state eq'wtg'; $print=1 if $options{grep} && /$options{grep}/; $print=0 if $options{exclude} && /$options{exclude}/; next unless /^ (\d+) ([D|I|F])\w+ +([a-zA-Z0-9]+)\.\d\d\d\d-\d\d-\d\d_\d\d\. \d\d\.\d\d_\d\d (.*)$/; my $id=$1; my $level=$2; my $host=$3; $state=$4; $state=~s/^is //; $print=($host eq $options{host}) ? 1 : 0 if $options{host}; next unless $print; if ($options{format} eq'std') { print "$_\n";} elsif ($options{format} eq'id') { print "$id\n";} elsif ($options{format} eq'delim') { print "$id:$level:$host:$state\n";} next unless $options{execute}; my $cmd=$options{execute}; $cmd=~s/!i/$id/g; $cmd=~s/!h/$host/g; $cmd=~s/!l/$level/g; $cmd=~s/!s/$state/g; my $reply=`$cmd`; print "reply from '$cmd' is:\n************\n$reply\n************\n" if $options{debug}; $resp=$?>>8; if ($resp) { print "response $resp returned from '$cmd'\n";} } if ($options{totals}) { my $total=$counts{rng}+$counts{wtg}; if ($options{format} eq'delim') { print "$counts{rng}:$counts{wtg}: $total\n";} else { print "$counts{rng} jobs running $counts{wtg} jobs waiting, total $total\n";} } sub help() { print "Usage: $prog <options> -mode <mode> Selects the run mode, one of rng, wtg, grep, jobs -r Sames as -mode rng. Lists all running jobs -w Same as -mode wtg. Lists all waiting jobs -j Same as -mode all. Lists all jobs If no mode is supplied, the program name is used. If called as bgrep the 1st argument is the search string -grep Supply a search string -excludes Supply a search string to exlude -host supply a host name to search for -incRng Include running jobs -incWtg Include waiting jobs The search priority is incRng,incWtg,grep,excludes host overrides all other criteria -format <format> Select the output format, one of std, id, delim, none The initial letter may be used -execute <cmd> Execute a command for each selected line - implies -format none unless overriden String substitution on the command has the following !i = ID !h = host !l = Level !s = status -cancel same as -execute bacula_cancel -debug Display debug information. Multiple calls increase the level -usage|help Display this help message "; exit; } # help # vim: ft=perl ai et =head1 NAME bjobs =head1 DESCRIPTION This program extracts the 'Running Jobs' section from the Bacula bconsole status output, and then lists the jobs with a running state (incl waiting for storage =head2 version history 2011-12-22 Initial creation 2012-09-13 Added despooling as a running state 2013-12-17 Version 2 complete rewrite to encorprage rng, wtg, bjobs and added all the other arguments. =cut -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk _______________________________________________ Bacula-users mailing list Bacula-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bacula-users