1"use strict";(globalThis.webpackChunkgo_c_8_y_cli=globalThis.webpackChunkgo_c_8_y_cli||[]).push([[15080],{6414(e,t,n){n.r(t),n.d(t,{assets:()=>o,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});const i=JSON.parse('{"id":"concepts/chaining-commands","title":"Chaining commands","description":"Most commands in go-c8y-cli support piped input (i.e. input from standard input (stdin)). This makes it easy to chain commands together.","source":"@site/docs/concepts/chaining-commands.md","sourceDirName":"concepts","slug":"/concepts/chaining-commands","permalink":"/docs/concepts/chaining-commands","draft":false,"unlisted":false,"editUrl":"https://github.com/reubenmiller/go-c8y-cli/edit/v2/docs/go-c8y-cli/docs/concepts/chaining-commands.md","tags":[],"version":"current","frontMatter":{"title":"Chaining commands"},"sidebar":"someSidebar","previous":{"title":"Caching","permalink":"/docs/concepts/caching"},"next":{"title":"Common Parameters","permalink":"/docs/concepts/common-parameters"}}');var s=n(74848),a=n(28453),r=(n(49489),n(7227),n(8157));const l={title:"Chaining commands"},c=void 0,o={},d=[{value:"Piping basics",id:"piping-basics",level:3},{value:"Piping to non-default flags (not supported in PSc8y)",id:"piping-to-non-default-flags-not-supported-in-psc8y",level:2},{value:"Find any events leading up to an alarm",id:"find-any-events-leading-up-to-an-alarm",level:3},{value:"Find devices by name",id:"find-devices-by-name",level:3},{value:"Assign multiple groups to the same user",id:"assign-multiple-groups-to-the-same-user",level:3},{value:"Examples",id:"examples",level:2},{value:"Piping ids",id:"piping-ids",level:3},{value:"Piping names",id:"piping-names",level:3},{value:"Creating devices",id:"creating-devices",level:3},{value:"Piping json",id:"piping-json",level:3},{value:"Chaining commands and using templates",id:"chaining-commands-and-using-templates",level:3},{value:"Piping inventory items and us multiple workers to speed up the action",id:"piping-inventory-items-and-us-multiple-workers-to-speed-up-the-action",level:3},{value:"Piping data from files",id:"piping-data-from-files",level:2},{value:"List of ids",id:"list-of-ids",level:3},{value:"List of names",id:"list-of-names",level:3},{value:"CSV list (first column with id)",id:"csv-list-first-column-with-id",level:3},{value:"JSON Lines",id:"json-lines",level:3}];function p(e){const t={admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.p,{children:"Most commands in go-c8y-cli support piped input (i.e. input from standard input (stdin)). This makes it easy to chain commands together."}),"\n",(0,s.jsx)(t.p,{children:"Previously in go-c8y-cli version 1, the PowerShell wrapper of go-c8y-cli was way to utilize piped data for passing data to downstream commands, for example:"}),"\n",(0,s.jsx)(r.A,{children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y devices list | c8y devices update --data "myValue=1"\n'})})}),"\n",(0,s.jsx)(t.p,{children:"With the go-c8y-cli version 2 release, pi
1peline input is now supported natively by the c8y binary. Taking the PowerShell example above, the same can be written in any shell (event PowerShell):"}),"\n",(0,s.jsx)(t.p,{children:"By supporting pipeline input, it enables greater flexibility as most of the commands outputs can be feed directly into another command without needing to save the output to a variable first, and in addition, it made it possible to support the following new features/optimizations:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["Concurrency (sending multiple requests at the same time) (via the ",(0,s.jsx)(t.code,{children:"workers <int>"})," parameter)"]}),"\n",(0,s.jsxs)(t.li,{children:["Progress indicators (via the ",(0,s.jsx)(t.code,{children:"progress"})," parameter)"]}),"\n",(0,s.jsx)(t.li,{children:"Reduction of calls to c8y binary (as the binary is only called once instead of once per input value)"}),"\n",(0,s.jsx)(t.li,{children:"Easy to feed data from files (i.e. list of ids or names)"}),"\n"]}),"\n",(0,s.jsx)(t.h3,{id:"piping-basics",children:"Piping basics"}),"\n",(0,s.jsx)(t.p,{children:"Let's say you want to lookup an inventory managed object using its id (because you copied it from the browser's url from one of Cumulocity's in-built applications). Normally if you are working with just a single id then you would use the following command:"}),"\n",(0,s.jsx)(r.A,{children:(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"c8y devices get --id 1234\n"})})}),"\n",(0,s.jsxs)(t.p,{children:["Now the same can be written using piped input by using the shell's ",(0,s.jsx)(t.code,{children:"echo"})," command as the input data will be mapped to the ",(0,s.jsx)(t.code,{children:"--id"})," parameter automatically. The parameter which will receive pipeline input is marked in the help with ",(0,s.jsx)(t.code,{children:"(accepts pipeline)"}),", but generally there should mostly be the obvious choice which parameter would make most sense (i.e. ",(0,s.jsx)(t.code,{children:"--id"}),", ",(0,s.jsx)(t.code,{children:"--device"})," etc.). A commands help text can be displayed by adding ",(0,s.jsx)(t.code,{children:"--help"})," to a command, i.e. ",(0,s.jsx)(t.code,{children:"c8y devices get --help"}),"."]}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'echo "1234" | c8y devices get\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'"1234" | batch | Get-Device\n'})})]}),"\n",(0,s.jsxs)(t.p,{children:["Now that does not seem so interesting as we are still fetching a single device and that is something Postman can do easily. Let's extend the command by now fetching 2 devices. Each id must be on a new line (so that it is treated as an independent value), so ",(0,s.jsx)(t.code,{children:"echo -e"})," will be used so that we can use the newline character ",(0,s.jsx)(t.code,{children:"\\n"})," to separate the two ids."]}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'echo -e "1234\\n5678" | c8y devices get\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"1234, 5678 | batch | Get-Device\n"})})]}),"\n",(0,s.jsxs)(t.p,{children:["Again not super interesting as who really wants to type multiple ids in every time you want to get the current values. So instead of echoing the ids, let's store them to file called ",(0,s.jsx)(t.code,{children:"ids.txt"})," (again one id per line):"]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-text",metastring:'title="file: ids.txt"',children:"1234\n5678\n"})}),"\n",(0,s.jsxs)(t.p,{children:["c8y won't read the file directly, however you can use ",(0,s.jsx)(t.code,{children:"cat"})," to read the file and it will pass contents of the file (line by line) to go-c8y-cli via the pipeline. By using a file it makes it easy to extend the list of ids by just appending new ids to it, and the command stays the same."]}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"cat ids.txt | c8y devices get\n"})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"Get-Content ids.txt | batch | Get-Device\n"})})]}),"\n",(0,s.jsx)(t.p,{children:'Though finding ids is annoying, so let\'s find the ids first and then store them to file, and this will act as our "watch list" that we want to use to occasionally fetch the updated information about these devices.'}),"\n",(0,s.jsxs)(t.p,{children:["So we can build the input ",(0,s.jsx)(t.code,{children:"ids.txt"})," file by doing a query by type and a custom fragment. We only want ot store the id, name and type of the devices so that the file remains relatively small, however the user has the name and type field to help identify which device the id is representing."]}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y devices list --type "myType*" --query "has(myCustomFragment)" --select id,name,type --output csv > ids.txt\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'Get-DeviceCollection -Type "myType*" -Query "has(myCustomFragment)" -Select id,name,type -Output csv > ids.txt\n'})})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-csv",metastring:'title="file: ids.txt"',children:"1234,My Device 1\n5678,My Device 2\n"})}),"\n",(0,s.jsxs)(t.p,{children:["This file can be piped in exactly the same way as go-c8y-cli is smart enough to detect that a csv file is given, and it only takes the first column of each row, using a ",(0,s.jsx)(t.code,{children:","})," (comma) delimiter."]}),"\n",(0,s.jsx)(t.p,{children:"Now saving ids to file is not always the way to go. It might be ok if you are dealing with devices, however for other Cumulocity entities, such as alarms, operations, events) it does not make too much sense as these entities are only interesting for a particular time period. So let's apply the same piping principles to handling operations."}),"\n",(0,s.jsxs)(t.p,{children:["For example, you are using Cumulocity and you notice there are a lot of pending operations for various devices in the platform. Most likely this occurred because the devices are offline for a longer period, or maybe the device agent does not recognize the operation type and left them in pending instead of cancelling them. You want to cancel the operations that are older than 14 days, however you don't want to delete them as you still want them to keep them for some following up analysis (deleting would be more efficient as there is a delete collection a
1pi, however you will lose the operation instead of the status just being set to ",(0,s.jsx)(t.code,{children:"FAILED"}),")."]}),"\n",(0,s.jsxs)(t.p,{children:["Saving the ids of the operations in the case does not make sense because you don't really care about the operation ids, you only care if the operation is in ",(0,s.jsx)(t.code,{children:"PENDING"})," and older than 14 days. So instead of saving the ids to file, you can just pipe the results from your operations query directly do the update operation command."]}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y operations list --status "PENDING" --dateTo "-14d" --includeAll | # get list of operations\n c8y operations update \\\n --status "FAILED" \\\n --failureReason "Cancelled stale operation as it was older than 14 days"\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'Get-OperationCollection -Status "PENDING" -DateTo "-14d" -IncludeAll | # get list of operations\n Update-Operation `\n -Status "FAILED" `\n -FailureReason "Cancelled stale operation as it was older than 14 days"\n'})})]}),"\n",(0,s.jsxs)(t.p,{children:["The first command ",(0,s.jsx)(t.code,{children:"c8y operations list"})," is responsible for getting the list of operations matching your search criteria. You can run the first part of the command first if you want to spot check the output to confirm that it behaves as you expect (though remove the ",(0,s.jsx)(t.code,{children:"includeAll"})," parameter if you don't want to spot check the entire list of operations)"]}),"\n",(0,s.jsxs)(t.p,{children:["By default, piped input will be processed serially (one after the other). If you want to speed things up you can use multiple workers (in this case let's use 5). We don't want to spam the platform, so we also set a delay of 250 milliseconds between each request processed by a single worker. Since we are potentially processing a large list of operations, we can also activate the progress indicator by using the ",(0,s.jsx)(t.code,{children:"progress"})," parameter."]}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y operations list --status "PENDING" --dateTo "-14d" --includeAll | # get list of operations\n c8y operations update \\\n --status "FAILED" \\\n --failureReason "Cancelled stale operation as it was older than 14 days" \\\n --workers 5 \\\n --delay 250 \\\n --progress\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'Get-OperationCollection -Status "PENDING" -DateTo "-14d" -IncludeAll | # get list of operations\n Update-Operation `\n -Status "FAILED" `\n -FailureReason "Cancelled stale operation as it was older than 14 days" `\n -Workers 5 `\n -Delay 250 `\n -Progress\n'})})]}),"\n",(0,s.jsxs)(t.p,{children:["A few notes about the usage of the progress indicator. When using the ",(0,s.jsx)(t.code,{children:"progress"})," parameter it will no longer write the response to standard output, however you can still redirect the output to file."]}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y operations list --status PENDING --dateFrom "-14d" |\n c8y operations update --progress > myoutput.json\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'Get-OperationCollection -Status PENDING -DateFrom "-14d" | batch |\n Update-Operation -Status -Progress > myoutput.json\n'})})]}),"\n",(0,s.jsx)(t.p,{children:"Before starting a command which will iterate over a large list of objects, it is helpful to first check how many objects exist to see if it aligns with your expectations to reduce the risk of modifying unexpected objects."}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y operations list --status "PENDING" --dateTo "-14d" --withTotalPages --pageSize 1\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'Get-OperationCollection -Status PENDING -DateFrom "-14d" -WithTotalPages -PageSize 1\n'})})]}),"\n",(0,s.jsx)(t.h2,{id:"piping-to-non-default-flags-not-supported-in-psc8y",children:"Piping to non-default flags (not supported in PSc8y)"}),"\n",(0,s.jsx)(t.admonition,{type:"note",children:(0,s.jsxs)(t.p,{children:["Custom pipeline mapping is supported from ",(0,s.jsx)(t.strong,{children:"c8y"})," \u2265 2.17.0"]})}),"\n",(0,s.jsx)(t.p,{children:"Most commands have a default flag which is marked as the default consumer of piped input. For most cases this is ok, however there are special cases where you might what to map the piped input to another flag."}),"\n",(0,s.jsxs)(t.p,{children:["The default pipeline variable c
1an be changed by using the ",(0,s.jsx)(t.code,{children:"-"})," (dash) character on the desired flag. The ",(0,s.jsx)(t.code,{children:"-"})," value will be substituted with the piped input (standard input) line by line."]}),"\n",(0,s.jsxs)(t.p,{children:["If the piped input is compressed JSON, then ",(0,s.jsx)(t.strong,{children:"c8y"})," will try to pick the correct property by a default list of properties defined internally on the command. If inbuilt properties do not match your use-case then you can specify a single or list of properties using the syntax ",(0,s.jsx)(t.code,{children:"-.prop1,.prop2"}),", then ",(0,s.jsx)(t.strong,{children:"c8y"})," will take the value form the first matching property."]}),"\n",(0,s.jsx)(t.admonition,{title:"Not supported in PowerShell",type:"warning",children:(0,s.jsx)(t.p,{children:"Custom piped input to flag mapping is not supported in PSc8y (PowerShell) cmdlets as PowerShell does not support this."})}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'# Pick plain text input\necho "t12345" | c8y applications list --providedFor -\n# => GET /application/applications?providedFor=t12345\n\n# Pick providerFor value from json input from either from .name or .tenant properties\necho "{\\"tenant\\":\\"t12345\\"}" | c8y applications list --providedFor -.name,.tenant\n# => GET /application/applications?providedFor=t12345\n'})}),"\n",(0,s.jsx)(t.h3,{id:"find-any-events-leading-up-to-an-alarm",children:"Find any events leading up to an alarm"}),"\n",(0,s.jsxs)(t.p,{children:["Image if there is a specific alarm and you would like to retrieve events leading up to the time of alarm. First you query for the alarm, and then pipe the value to the events command, and pipe the alarm's timestamp to the ",(0,s.jsx)(t.code,{children:"dateFrom"})," flag."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"c8y alarms list --type myCriticalAlarm --pageSize 1 \\\n| c8y events list --dateTo -.time\n\n# If you want to limit to a single device,\n# then you need to provide device in both commands\nc8y alarms list --type myCriticalAlarm --pageSize 1 --device 12345 \\\n| c8y events list --dateTo -.time --device 12345\n"})}),"\n",(0,s.jsx)(t.h3,{id:"find-devices-by-name",children:"Find devices by name"}),"\n",(0,s.jsxs)(t.p,{children:["Map the piped input to the ",(0,s.jsx)(t.code,{children:"--name"})," flag, which simplifies the command usage without having to explicitly pipe the whole inventory query (as ",(0,s.jsx)(t.code,{children:"--query"})," is consumes the piped input by default)."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"echo -e \"linuxdevice01\\nlinuxdevice02\" | c8y devices list --name -\n# => GET /inventory/managedObjects?q=$filter=(name eq 'linuxdevice01') $orderby=name\n# => GET /inventory/managedObjects?q=$filter=(name eq 'linuxdevice02') $orderby=name\n"})}),"\n",(0,s.jsx)(t.h3,{id:"assign-multiple-groups-to-the-same-user",children:"Assign multiple groups to the same user"}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.code,{children:"c8y userreferences addUserToGroup"})," normally accepts piped input via the ",(0,s.jsx)(t.code,{children:"--user"})," flag, which results in add a single group to multiple users."]}),"\n",(0,s.jsxs)(t.p,{children:["However if you would like to assign multiple groups to a single user, then the piped input can be assigned to the ",(0,s.jsx)(t.code,{children:"--group"})," flag using the example below."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'# Add assign multiple groups to a single user\necho -e "admins\\nbusiness" | c8y userreferences addUserToGroup --user [email protected] --group -\n\n# Or assign multiple users to a single group\necho -e "user01\\nuser02" | c8y userreferences addUserToGroup --group admins\n'})}),"\n",(0,s.jsx)(t.h2,{id:"examples",children:"Examples"}),"\n",(0,s.jsx)(t.h3,{id:"piping-ids",children:"Piping ids"}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'echo
1-e "12345\\n22222" | c8y inventory get\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"12345, 22222 | batch | Get-ManagedObject\n"})})]}),"\n",(0,s.jsx)(t.h3,{id:"piping-names",children:"Piping names"}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'echo -e "device01\\ndevice02" | c8y inventory get\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'"device01", "device02" | batch | Get-ManagedObject\n'})})]}),"\n",(0,s.jsx)(t.h3,{id:"creating-devices",children:"Creating devices"}),"\n",(0,s.jsxs)(t.p,{children:["Use the ",(0,s.jsx)(t.code,{children:"c8y util repeat"})," command to create 5 devices names, then pipe the names to ",(0,s.jsx)(t.code,{children:"c8y devices create"})]}),"\n",(0,s.jsxs)(r.A,{transform:"false",children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y util repeat 5 --format "device_%s%04s" |\n c8y devices create --template "{ other_props: {}, type: \'ci_Test\' }" \\\n --select id,name,type\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'c8y util repeat 5 --format "device_%s%04s" |\n batch |\n New-Device -Template "{ other_props: {}, type: \'ci_Test\' }" -Select id,name,type\n'})})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",metastring:'title="output"',children:"| id | name | type |\n|-----------------------|----------------------------|------------------------|\n| 481033 | device_0001 | ci_Test |\n| 481034 | device_0002 | ci_Test |\n| 480956 | device_0003 | ci_Test |\n| 481035 | device_0004 | ci_Test |\n| 480860 | device_0005 | ci_Test |\n"})}),"\n",(0,s.jsxs)(t.admonition,{title:"Shell Users",type:"tip",children:[(0,s.jsxs)(t.p,{children:["Alternatively the linux command ",(0,s.jsx)(t.code,{children:"seq"})," can be used to create devices names to be piped to the create command."]}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"seq -f device_%04g 6 10 |\n c8y devices create --template \"{ other_props: {}, type: 'ci_Test' }\" --select id,name,type\n"})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",metastring:'title="output"',children:"| id | name | type |\n|-----------------------|----------------------------|------------------------|\n| 481036 | device_0006 | ci_Test |\n| 480957 | device_0007 | ci_Test |\n| 481037 | device_0008 | ci_Test |\n| 480861 | device_0009 | ci_Test |\n| 480862 | device_0010 | ci_Test |\n"})})]}),"\n",(0,s.jsx)(t.h3,{id:"piping-json",children:"Piping json"}),"\n",(0,s.jsx)(t.p,{children:"c8y also accepts piped json input (each line must represent a json object, this is automatically handled by c8y when piping to other c8y commands)"}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y inventory find --query="not(has(myTag))" |\n c8y inventory update --data "myTag={}" --dry\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'Find-ManagedObject -Query="not(has(myTag))" | batch |\n Update-ManagedObject -Data "myTag={}" -Dry\n'})})]}),"\n",(0,s.jsx)(t.p,{children:"Or if you are just want to update a single item"}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y inventory get --id=12345 | c8y inventory update --data "myTag={}" --dry\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'Get-ManagedObject -Id 12345 | Update-ManagedObject -Data "myTag={}" -Dry\n'})})]}),"\n",(0,s.jsx)(t.h3,{id:"chaining-commands-and-using-templates",children:"Chaining commands and using templates"}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'c8y devices create --name "myname" |\n c8y identity create --type c8y_Serial --template "{ externalId: input.value.name }"\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'New-Device -Name "myname" |\n New-ExternalId -Type c8
1y_Serial -Template "{ externalId: input.value.name }"\n'})})]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",metastring:'title="output"',children:"| type | externalId | managedObject.id |\n|-----------------|-------------|------------------|\n| c8y_Serial | myname | 484203 |\n"})}),"\n",(0,s.jsx)(t.h3,{id:"piping-inventory-items-and-us-multiple-workers-to-speed-up-the-action",children:"Piping inventory items and us multiple workers to speed up the action"}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"c8y inventory list --pageSize 15 | c8y inventory get --workers 5\n"})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"Get-ManagedObjectCollection -PageSize 15 | batch | Get-ManagedObject -Workers 5\n"})})]}),"\n",(0,s.jsx)(t.p,{children:"However if you are getting a list of devices, then you can just pipe the values directly"}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:'echo "1111\\n2222" | c8y inventory get | c8y devices get --workers 1\n'})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:'"1111", "2222" | batch | Get-ManagedObject -Workers 1\n'})})]}),"\n",(0,s.jsx)(t.h2,{id:"piping-data-from-files",children:"Piping data from files"}),"\n",(0,s.jsx)(t.p,{children:"The following show examples of the support files inputs that can be piped to c8y commands. All of the examples retrieve operations related to each input device."}),"\n",(0,s.jsx)(t.h3,{id:"list-of-ids",children:"List of ids"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",metastring:'title="file: ids.txt (Comma Separated Variables (csv) - comma delimited)"',children:"1111\n2222\n3333\n4444 \n"})}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"cat input.txt | c8y operations list\n"})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"Get-Content input.txt | batch | Get-OperationCollection\n"})})]}),"\n",(0,s.jsx)(t.h3,{id:"list-of-names",children:"List of names"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",metastring:'title="file: names.txt (Comma Separated Variables (csv) - comma delimited)"',children:"MyActualName1\nMyActualName2\nMyActualName3\nMyActualName4 \n"})}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"cat names.txt | c8y operations list\n"})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"Get-Content names.txt | batch | Get-OperationCollection\n"})})]}),"\n",(0,s.jsx)(t.h3,{id:"csv-list-first-column-with-id",children:"CSV list (first column with id)"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-csv",metastring:'title="file: input.txt (Comma Separated Variables (csv) - comma delimited)"',children:"1111,MyActualName1\n2222,MyActualName2\n3333,MyActualName3\n4444,MyActualName4 \n"})}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"cat input.txt | c8y operations list\n"})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"Get-Content input.txt | batch | Get-OperationCollection\n"})})]}),"\n",(0,s.jsx)(t.h3,{id:"json-lines",children:"JSON Lines"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-json",metastring:'title="file: input.json (JSON lines)"',children:'{"name": "MyActualName1", "id": "1111", "c8y_Hardware": {"serialNumber": "UNIQUE_ID_1"}}\n{"name": "MyActualName2", "id": "2222", "c8y_Hardware": {"serialNumber": "UNIQUE_ID_2"}}\n{"name": "MyActualName3", "id": "3333", "c8y_Hardware": {"serialNumber": "UNIQUE_ID_3"}}\n{"name": "MyActualName4", "id": "4444", "c8y_Hardware": {"serialNumber": "UNIQUE_ID_4"}} \n'})}),"\n",(0,s.jsxs)(r.A,{children:[(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-bash",children:"cat input.json | c8y operations list\n"})}),(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-powershell",children:"Get-Content input.json | batch | Get-OperationCollection\n"})})]})]})}function h(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},7227(e,t,n){n.d(t,{A:()=>r});n(96540);var i=n(34164);const s="tabItem_Ymn6";var a=n(74848);function r(e){let{children:t,hidden:n,className:r}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,i.A)(s,r),hidden:n,children:t})}},49489(e,t,n){n.d(t,{A:()=>A});var i=n(96540),s=n(34164),a=n(18630),r=n(24245),l=n(56347),c=n(36494),o=n(62814),d=n(45167),p=n(69900);function h(e){return i.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,i.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs>
1 child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:t,children:n}=e;return(0,i.useMemo)((()=>{const e=t??function(e){return h(e).map((e=>{let{props:{value:t,label:n,attributes:i,default:s}}=e;return{value:t,label:n,attributes:i,default:s}}))}(n);return function(e){const t=(0,d.XI)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function g(e){let{queryString:t=!1,groupId:n}=e;const s=(0,l.W6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,o.aZ)(a),(0,i.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function y(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=u(e),[r,l]=(0,i.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const i=n.find((e=>e.default))??n[0];if(!i)throw new Error("Unexpected error: 0 tabValues");return i.value}({defaultValue:t,tabValues:a}))),[o,d]=g({queryString:n,groupId:s}),[h,y]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,p.Dv)(n);return[s,(0,i.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),v=(()=>{const e=o??h;return m({value:e,tabValues:a})?e:null})();(0,c.A)((()=>{v&&l(v)}),[v]);return{selectedValue:r,selectValue:(0,i.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),y(e)}),[d,y,a]),tabValues:a}}var v=n(11062);const x="tabList__CuJ",j="tabItem_LNqP";var f=n(74848);function b(e){let{className:t,block:n,selectedValue:i,selectValue:a,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:o}=(0,r.a_)(),d=e=>{const t=e.currentTarget,n=c.indexOf(t),s=l[n].value;s!==i&&(o(t),a(s))},p=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=c.indexOf(e.currentTarget)+1;t=c[n]??c[0];break}case"ArrowLeft":{const n=c.indexOf(e.currentTarget)-1;t=c[n]??c[c.length-1];break}}t?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:i===t?0:-1,"aria-selected":i===t,ref:e=>{c.push(e)},onKeyDown:p,onClick:d,...a,className:(0,s.A)("tabs__item",j,a?.className,{"tabs__item--active":i===t}),children:n??t},t)}))})}function w(e){let{lazy:t,children:n,selectedValue:a}=e;const r=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=r.find((e=>e.props.value===a));return e?(0,i.cloneElement)(e,{className:(0,s.A)("margin-top--md",e.props.className)}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:r.map(((e,t)=>(0,i.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function N(e){const t=y(e);return(0,f.jsxs)("div",{className:(0,s.A)(a.G.tabs.container,"tabs-container",x),children:[(0,f.jsx)(b,{...t,...e}),(0,f.jsx)(w,{...t,...e})]})}function A(e){const t=(0,v.A)();return(0,f.jsx)(N,{...e,children:h(e.children)},String(t))}}
1,8157(e,t,n){n.d(t,{A:()=>x});n(96540);var i=n(49489),s=n(7227),a=n(57254),r=n(28453),l=n(7710),c=n(71765),o=n(82898),d=n(74848);const p=c.Zj.github,h=c.Zj.dracula,u={"c8y alarms create":"New-Alarm","c8y alarms get":"Get-Alarm","c8y alarms delete":"Remove-Alarm","c8y alarms subscribe":"Watch-Alarm","c8y alarms list":"Get-AlarmCollection","c8y alarms count":"Get-AlarmCount","c8y events create":"New-Event","c8y events get":"Get-Event","c8y events delete":"Remove-Event","c8y events subscribe":"Watch-Event","c8y events list":"Get-EventCollection","c8y events downloadBinary":"Get-EventBinary","c8y measurements create":"New-Measurement","c8y operations create":"New-Operation","c8y operations get":"Get-Operation","c8y operations update":"Update-Operation","c8y operations delete":"Remove-Operation","c8y operations subscribe":"Watch-Operation","c8y operations list":"Get-OperationCollection","c8y auditrecords create":"New-AuditRecord","c8y auditrecords get":"Get-AuditRecord","c8y auditrecords delete":"Remove-AuditRecord","c8y auditrecords subscribe":"Watch-AuditRecord","c8y auditrecords list":"Get-AuditRecordCollection","c8y devices create":"New-Device","c8y devices list":"New-DeviceCollection","c8y devices get":"Get-Device","c8y devices update":"Update-Device","c8y devices delete":"Remove-Device","c8y devices setRequiredAvailability":"Set-DeviceRequiredAvailability","c8y agents create":"New-Agent","c8y agents list":"Get-AgentCollection","c8y agents get":"Get-Agent","c8y agents update":"Update-Agent","c8y agents delete":"Remove-Agent","c8y inventory create":"New-ManagedObject","c8y inventory get":"Get-ManagedObject","c8y inventory update":"Update-ManagedObject","c8y inventory list":"Get-ManagedObjectCollection","c8y inventory find":"Find-ManagedObjectCollection","c8y inventory findByText":"Find-ByTextManagedObjectCollection","c8y devicegroups create":"New-DeviceGroup","c8y devicegroups list":"Get-DeviceGroupCollection","c8y devicegroups listAssets":"Get-DeviceGroupChildAssetCollection","c8y devicegroups children assign":"Add-DeviceGroupChild","c8y devicegroups children unassign":"Remove-DeviceGroupChild","c8y devicegroups assignDevice":"Add-DeviceToGroup","c8y devicegroups unassignDevice":"Remove-DeviceFromGroup","c8y applications create":"New-Application","c8y applications createHostedApplication":"New-HostedApplication","c8y applications list":"Get-ApplicationCollection","c8y applications get":"Get-Application","c8y applications update":"Update-Application","c8y applications delete":"Remove-Application","c8y software versions install":"Install-SoftwareVersion","c8y software versions uninstall":"Remove-SoftwareVersion","c8y binaries get":"Get-Binary","c8y microservices get":"Get-Microservice","c8y microservices list":"Get-MicroserviceCollection","c8y microservices update":"Update-Microservice","c8y microservices delete":"Delete-Microservice","c8y microservices create":"New-Microservice","c8y microservices enable":"Enable-Microservice","c8y microservices disable":"Disable-Microservice","c8y microservices getBootstrapUser":"Get-MicroserviceBootstrapUser","c8y notification2 subscriptions create":"New-Notification2Subscription","c8y notification2 subscriptions subscribe":"Watch-Notification2Subscription","c8y notification2 tokens create":"New-Notification2Token","c8y template execute":"Invoke-Template","c8y sessions create":"New-Session","c8y currentuser get":"Get-CurrentUser","set-session":"Set-Session","cat ":"Get-Content ","-o csv":"--output csv","-o json":"--output json","-p ":"--pageSize "},m={"rm ":"Remove-Item "};function g(e,t){const n=Object.keys(t);for(let r=0;r<n.length;r++){const l=t[n[r]];i=e,s=n[r],a=l,e=i.split(s).join(a)}var i,s,a;return e=e.replace(/\\/g,"`")}const y=e=>{let{children:t,className:n="bash",live:i=!1,render:s=!1,transform:c=!1}=e;const{colorMode:y}=(0,l.G)(),v="dark"===y;if(i)return(0,d.jsx)("div",{style:{marginTop:"40px"},children:(0,d.jsxs)(a.Q,{code:t.trim(),transformCode:e=>"/** @jsx mdx */"+e,scope:{MDXProvider:r.x},children:[(0,d.jsx)(a.pA,{}),(0,d.jsx)(a.w,{}),(0,d.jsx)(a.p1,{})]})});if(s)return(0,d.jsx)("div",{style:{marginTop:"40px"},children:(0,d.jsx)(a.Q,{code:t,children:(0,d.jsx)(a.pA,{})})});let x="";var j;t&&"function"==typeof t.trim&&(x=t.trim(),"powershell"===n&&("true"==`${c}`&&(x=function(e){void 0===e&&(e="");let t=g(e,u).split(" ");if(t.length)for(let n=0;n<t.length;n++)t[n].startsWith("--")?t[n]="-"+t[n].substring(2,3).toUpperCase()+t[n].substring(3):t[n].startsWith("-");return t.join(" ")}(t.trim())),void 0===(j=x)&&(j=""),x=g(j,m).split(" ").join(" "),x=x.replace(/\\/g,"`")));const f=v?h:p;return(0,d.jsx)(o.A,{className:n,theme:f,children:x})},v=[{label:"Shell",value:"bash"},{label:"PowerShell (native)",value:"powershell"},{label:"PowerShell (PSc8y)",value:"powershell_psc8y"}],x=e=>{let t,n,a,{transform:r=!0,...l}=e;return 3==l.children.length?(t=l.children[0].props.children.props.children,n=l.children[1].props.children.props.children,a=l.children[2].props.children.props.children):2==l.children.length?(t=l.children[0].props.children.props.children,n=t,a=l.children[1].props.children.props.children):1==l.children.length?(t=l.children[0].props.children.props.children,n=t,a=t):(t=l.children.props.children.props.children,n=t,a=t),(0,d.jsxs)(i.A,{groupId:"shell-types",defaultValue:"bash",values:v,children:[(0,d.jsx)(s.A,{value:"bash",children:(0,d.jsx)(y,{render:!1,className:"bash",transform:!1,children:t})}),(0,d.jsx)(s.A,{value:"powershell",children:(0,d.jsx)(y,{render:!1,className:"powershell",transform:!1,children:n})}),(0,d.jsx)(s.A,{value:"powershell_psc8y",children:(0,d.jsx)(y,{render:!1,className:"powershell",transform:r,children:a})})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.