简体   繁体   English

如何在 Rundeck 上为列表中的每个用户运行作业?

[英]How can I run a job on Rundeck for each user in the list?

I want to create a scheduled job on Rundeck.我想在 Rundeck 上创建一个预定的作业。 Rundeck Job runs the script that does some staff for a single user I have in my list. Rundeck Job 运行脚本,为列表中的单个用户执行一些工作。

So job has an input parameter - username.所以job有一个输入参数——用户名。 I need to run that job for all users in my list, but not to process it in one job execution.我需要为列表中的所有用户运行该作业,而不是在一个作业执行中处理它。 I need a separate job execution for each user.我需要为每个用户单独执行作业。

Providing an example to make it more clear:
For instance, I have 3 users: user1, user2, user3.

    
I have a job that does some processing for that users and running it with parameter (unsername). 
I need to create a scheduled job that will be run for each user.

 1. Running job with user1 parameter
 2. Running job with user2 parameter
 3. Running job with user3 parameter

Is there anyway to do that?有没有办法做到这一点?

You can design a workflow with a list option to use on any step (like command, inline-script or script), I did an example with a list option (users) and example inline-script that do some action for each user, the job is scheduled.您可以设计一个带有列表选项的工作流以在任何步骤(如命令、内联脚本或脚本)上使用,我做了一个带有列表选项(用户)的示例和为每个用户执行一些操作的示例内联脚本,作业已安排。

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='users' required='true' value='alice,bob,charlie,david' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>e62a25a0-b67c-4bb7-8721-c96b7e4cb9f5</id>
    <loglevel>INFO</loglevel>
    <name>JobEXAMPLE</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <schedule>
      <month month='*' />
      <time hour='12' minute='0' seconds='0' />
      <weekday day='*' />
      <year year='*' />
    </schedule>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[#!/bin/bash

myusers=@option.users@
Field_Separator=$IFS
 
# set comma as the internal field separator for the string list
IFS=,
for value in $myusers;
do
    echo "action for $value"
done
 
IFS=$Field_Separator]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>e62a25a0-b67c-4bb7-8721-c96b7e4cb9f5</uuid>
  </job>
</joblist>

Here the result.结果在这里

Maybe this interest you.也许让你感兴趣。 Also, data values work in this case.此外, 数据值在这种情况下也有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM