VMware Cloud Community
filosmith
Enthusiast
Enthusiast

vRO Command execution

I'm trying to use a Command() to execute nsupdate on my vRO server, which is either interactive or can read a file for its commands. I'd rather not have to write a file of commands for nsupdate to run.

In a shell I would do:

nsupdate <<EOF

command

command

command

EOF

How can I send those returns in a crafted command in Orchestrator?

I've tried

'nsupdate <<EOF

command

command

command

EOF';

but vRO won't even attempt that because I guess it can't take multi-line strings.

I've also tried

'nsupdate <<EOF\ncommand\ncommand\ncommand\nEOF';

and

'nsupdate <<EOF^Jcommand^Jcommand^Jcommand^JEOF';

Thanks.

Tags (1)
Reply
0 Kudos
11 Replies
eoinbyrne
Expert
Expert

Have you tried putting the whole command line into a script and calling that with a vRO Command?

e.g.,

script like this (say named myNsupate.sh)

#!/bin/bash

nsupdate <<EOF 

command 

command 

command 

EOF

Then use a Command object to call that?

Reply
0 Kudos
filosmith
Enthusiast
Enthusiast

I'd rather not have to write a file first and then execute it, if at all possible. I will try that if it's impossible.

Reply
0 Kudos
eoinbyrne
Expert
Expert

Sorry, missed the bit where you said the commands were variable....

Possibly a double whammy approach here in a single vRO workflow

1. Obtain a workflow lock

2. Write a file to the local filesystem with the commands in it - 1 per line, name of the file will be important so keep that in a JS var named cmdFile

3. Execute the Command like this

var cmd = new Command("nsupdate " + cmdFile);

cmd.execute();

4. Release the workflow lock

You need the lock so that parallel invocations don't clobber the command file as you write it

Reply
0 Kudos
filosmith
Enthusiast
Enthusiast

Trying this:

var cmd =    '(/bin/echo "server ' + dnsServer + '";' +

            '/bin/echo "prereq nxrrset ' + hostname + '.fqdn.com. CNAME";' +

            '/bin/echo "update add ' + hostname + '.fqd.com. 3600 A ' + address + '";' +

            '/bin/echo "update add ' + reverseAddress + '.in-addr.arpa. 3600 PTR ' + hostname + '.fqdn.com";' +

            '/bin/echo "send") | /bin/nsupdate';

I get this:

Error in (Workflow:nsupdate / Scriptable task (item1)#39) Wrapped java.io.IOException: Cannot run program "(/bin/echo": error=2, No such file or directory

Reply
0 Kudos
eoinbyrne
Expert
Expert

Have you configured the js-io-rights to permit vRO to read from "/bin"?  + also, does the 'echo' binary exist at that location on the server? (You can find out but doing "which echo" at the terminal prompt as any user)

The Command processing has some built-in scope to permit read/write/execute of anything in the default PATH of the shell. However, by adding the absolute path to 'echo' binary there you force the Command environment to read it from the specific path. So, the error here says that the 'echo' command was not found and this was either because it is NOT at the given location OR, that the io-rights are not set to allow reading from '/bin' (NOTE:  - on my test node in workstation it IS @ /bin/echo so it's probably the io-rights)

This page should help - Work Space: vRO 7.# - Enabling local script or command execution in vRealize Orchestrator (Not my blog, but it is useful)

HTH

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

The Command object is not a full replacement for a BASH shell. So when you use parentheses around commands to start a sub-shell and execute commands from the list in this sub-shell, the execution is likely to fail.

Could you try instead to launch a BASH and pass the command to it, something like /bin/bash -c 'your commands here'

filosmith
Enthusiast
Enthusiast

It is getting closer, but doesn't make it past the pipe. However, if I paste the exact same thing into a shell, it works.

var cmd =    '/bin/bash -vc echo "server ' + dnsServer + '"&&' +

            'echo "prereq nxrrset ' + hostname + '.fqdn.com. CNAME"&&' +

            'echo "update add ' + hostname + '.fqdn.com. 3600 A ' + address + '"&&' +

            'echo ""&&' +

            'echo "update delete ' + reverseAddress + '.in-addr.arpa. PTR"&&' +

            'echo "update add ' + reverseAddress + '.in-addr.arpa. 3600 PTR ' + hostname + '.fqdn.com"&&' +

            'echo "send" | /usr/bin/nsupdate';

[2018-05-22 09:08:52.973] [D] cmd:

/bin/bash -vc echo "server #.#.#.#"&&echo "prereq nxrrset hostname.fqdn.com. CNAME"&&echo "update add hostname.fqdn.com. 3600 A #.#.#.#"&&echo ""&&echo "update delete #.#.#.#.in-addr.arpa. PTR"&&echo "update add #.#.#.#.in-addr.arpa. 3600 PTR hostname.fqdn.com"&&echo "send" | /usr/bin/nsupdate

Reply
0 Kudos
filosmith
Enthusiast
Enthusiast

That returns 0 but doesn't actually update DNS.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

I think the command text after -vc should be enclosed in single quotes (escaped with \ to make the string concatenation valid).

Something like:

var cmd =    '/bin/bash -vc \'echo "server ' + dnsServer + '"&&'

            'echo "prereq nxrrset ' + hostname + '.fqdn.com. CNAME"&&'

            'echo "update add ' + hostname + '.fqdn.com. 3600 A ' + address + '"&&'

            'echo ""&&'

            'echo "update delete ' + reverseAddress + '.in-addr.arpa. PTR"&&'

            'echo "update add ' + reverseAddress + '.in-addr.arpa. 3600 PTR ' + hostname + '.fqdn.com"&&'

            'echo "send" | /usr/bin/nsupdate\'';

Reply
0 Kudos
filosmith
Enthusiast
Enthusiast

Yeah, I tried that first. It generates bash error 2 "Misuse of shell builtins"

Reply
0 Kudos
filosmith
Enthusiast
Enthusiast

This just echoes everything, including the | and nsupdate:

var cmd =    'echo -e \'server ' + dnsServer + '\n' +

            'prereq nxrrset ' + hostname + '.fqdn.com. CNAME\n' +

            'update add ' + hostname + '.fqdn.com. 3600 A ' + address + '\n' +

            '\n' +

            'update delete ' + reverseAddress + '.in-addr.arpa. PTR\n' +

            'update add ' + reverseAddress + '.in-addr.arpa. 3600 PTR ' + hostname + '.fqdn.com\n' +

            'send\' | /usr/bin/nsupdate';

[2018-05-22 12:50:32.060] [D] cmd:

echo -e 'server #.#.#.#

prereq nxrrset hostname.fqdn.com. CNAME

update add hostname.fqdn.com. 3600 A #.#.#.#

update delete #.#.#.#.in-addr.arpa. PTR

update add #.#.#.#.in-addr.arpa. 3600 PTR hostname.fqdn.com

send' | /usr/bin/nsupdate

[2018-05-22 12:50:32.066] [D] result: 0

[2018-05-22 12:50:32.067] [D] output: 'server #.#.#.#

prereq nxrrset hostname.fqnd.com. CNAME

update add hostname.fqnd.com. 3600 A #.#.#.#

update delete #.#.#.#.in-addr.arpa. PTR

update add #.#.#.#.in-addr.arpa. 3600 PTR hostname.fqdn.com

send' | /usr/bin/nsupdate

Reply
0 Kudos