Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Using iwqueryjobs with a query
robertito
I want a list of all the jobs that are owned by a particular user.
The command line tools documentation states that all the queries must be in a particular XML format, but it doesn't provide any examples of how to include the query structure into the command line arguments. In addition, the iwqueryjobs -h command just says that the queries are read from the STDIN.
Can somebody provide me with an example?
Find more posts tagged with
Comments
Migrateduser
Here's an email response I sent to someone asking about something similar for the iwquerytasks CLT. You can incorporate the same technique for iwqueryjobs.
There is a way to use the CLT iwquerytasks that you can use from within a script without using STDIN. It's a little funky to use, but here's one way to do it. I tend to be impatient, so once I find a way to get something to work, I don't try to
find the most efficient way, so there may be an easier way. That's my disclaimer. The command reads an XML formatted request, which I read in from a file instead of STDIN. Here's an example.
I do this programmatically because it's part of a custom menu item that allows people to look at their open tasks. I build the XML dynamically, because you never know who the user will be. Here's the perl code to do this:
my $tasks_infile = '/interwoven/iw-home/httpd/iw-bin/iwquerytasks.input';
open OUTFILE, ">$tasks_infile";
print OUTFILE <<END;
<taskquery>
<and>
<ownedby v="$user"/>
<active/>
</and>
</taskquery>
END
close OUTFILE;
# Get the active tasks for this user
my
@active_tasks
= `/interwoven/iw-home/bin/iwquerytasks < $tasks_infile`;
The resulting $tasks_infile looks like this, assuming the user ID is "dsmith":
<taskquery>
<and>
<ownedby v="dsmith"/>
<active/>
</and>
</taskquery>
What gets returned is a list of task IDs that are active for that user. You can take a look at the CLT manual for iwquerytasks for all DTD of the input format. Although it isn't documented very well with lots of examples, all you need to know is there. There's also a similar CLT called iwqueryjobs which does the same thing for jobs.
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
ONLINEHELP.jpg
robertito
Thanks for your help. With what I was able to garner from your example, I wrote the following ipl:
#This code snippet will search for all the jobs assigned to a user and delete them
#Example: Delete all the jobs assigned to user "rhelliar"
#Usage: /usr/iw-home/iw-perl/bin/iwperl /usr/iw-home/bin/iwqueryjob.ipl rhelliar
my $tasks_infile = '/usr/iw-home/bin/iwqueryjobs.input';
my $user = $ARGV[0];
open OUTFILE, ">$tasks_infile";
print OUTFILE <<END;
<wfquery>
<and>
<ownedby v="$user"/>
<active/>
</and>
</wfquery>
END
close OUTFILE;
# Get the active tasks for this user
my
@job_array
= `/usr/iw-home/bin/iwqueryjobs < $tasks_infile`;
foreach $i (
@job_array)
{
#The next line of code will remove each of the jobs directly
`/usr/iw-home/bin/iwrmjob $i`;
print "Deleted job number: " . $i;
}
I've noticed that you respond to a lot of questions. Thanks for taking the time to help other people out.
Migrateduser
My pleasure to help out. Hopefully most of the stuff I tell people actually works
I assume this did the trick for you then? That's a pretty nasty script you have there - deleting all of a person's jobs. I certainly hope you have some good checks before you run that one.
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
Adam Stoller
I second Smitty's concern regarding making sure you're doing what you want *before* you delete those jobs.
I would also suggest you make your comments more correct - your comments indicate that you are looking for tasks, but you're using iwqueryjobs. While *you* may know what this is for right now - a month from now, or if someone else ends up trying to make sense of it - it could be rather confusing.
Also - you don't need to do a foreach on the
@job_array
- iwrmjob takes multiple jobids (space separated) - and thus it would be a bit more efficient. However, having said that, you might need to break up the list into multiple commands if the length of the command (in total) exceeds the lenght allowed for a command and command line arguments (I think it's something like 256) [you only need to worry about this if you expect to be deleting over 50 or so jobs at a time]
I have a similar script that I use for clearing out all my jobs during testing on my laptop (i.e. a non-production system) - which looks like this:
while(
@job_array){
my $job_array = "";
while(length($job_array) < 200){
$job_array .= shift(
@job_array)
. " ";
}
`$iwhome/bin/iwrmjob $job_array`;
print "$job_array\n";
}
Not beautiful - but I figure it's nicer than erroring out...
--fish
(Interwoven, Curriculum Development)