Ask Your Question
0

capture output of command execute

asked 2015-11-09 08:22:15 -0500

wrkilu gravatar image

Hi,

I use mcollective for connecting with agents and managing immediately. Now I need to execute command on agent and capture output of it. I haven't foung any way in google for it. So question... how to capture output of remote command e.g. "ls -l /"

Thanks, wrkilu

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2015-11-10 01:18:09 -0500

wrkilu gravatar image

Joyce... thanks for trying but I know that ;). The problem is in Puppet. How to grab this output on master while command executing is on agent ?

edit flag offensive delete link more
0

answered 2015-11-09 19:09:02 -0500

Joyce gravatar image

Hi wrkilu,

When I want to redirect output from a Linux command line into a file (capture the output of a command), I use redirection (>).

For example:

ls -l / > /path/to/log/dir/filename.log 2>&1

where:

the command is: ls -l /

the greater than symbol (>) tells it to put the output (stdout) into the following file

the filename is: /path/to/log/dir/filename.log (This can be the full path or the relative path with the filename at the end.

2>&1: This tells it to send stderr (error messages) to the same address as stdout (output). That way stdout and stderr both go in the file you gave it. (0 = stdin; 1 = stdout; 2 = stderr; & = address)

I think you should be able to use the same syntax when you use the agent to execute a command.

Hope this helps, Joyce

edit flag offensive delete link more
0

answered 2015-11-10 09:43:00 -0500

chsnell gravatar image

If you're looking to have Puppet act upon that output, then it has to either come through facter prior to the Puppet run (check out https://ask.puppetlabs.com/question/1...) or handled within your exec script. If you're just looking for centralized logging of the command, I would suggest that Puppet is not the right tool for that. Perhaps you could expand upon why you need to capture that output.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-11-09 08:22:15 -0500

Seen: 737 times

Last updated: Nov 10 '15