Ask Your Question
0

How to execute two commands one after the other in puppet program

asked 2017-06-15 02:23:29 -0500

rohithmn03 gravatar image

updated 2017-06-15 02:24:04 -0500

Hi Team,

below is my puppet program snippet..!: FYI...

exec {'unpack_splunk_forwarder.tar.gz':
        unless => 'test -f /opt/splunkforwarder/bin/splunk',
        cwd => '/opt',
        command => 'gunzip /opt/splunkforwarder.tar.gz && tar -xvf /opt/splunkforwarder.tar',
    }

in command attribute i have specified two commands with && (AND) condition between them. Ideally i want gunzip command to executed first and then tar command. But i guess both are executing simultaneously. How could i solve this problem..!?

Please help here..!

Regards, Rohith

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
1

answered 2017-06-15 21:16:42 -0500

bschonecker gravatar image

You could pipe the STDOUT from the gzip command directly to tar and avoid two separate commands:

gunzip --to-stdout /opt/splunkforwarder.tar.gz | tar -xvf -

Note, I'm doing this from memory so it may not work exactly as i've typed.

edit flag offensive delete link more

Comments

Hi, Thanks much it really worked for me..! :)

rohithmn03 gravatar imagerohithmn03 ( 2017-06-15 21:46:25 -0500 )edit
2

answered 2017-06-15 04:44:35 -0500

rajeevsharma gravatar image

Hi Rohit, I guess there are many ways this can be done. First of all why don't you use tar -zxvf to avoid gunzip? If you want to combine gunzip and tar both then instead of && you can use a single ; (semicolon)So the code would be command => 'gunzip /opt/splunkforwarder.tar.gz ; tar -xvf /opt/splunkforwarder.tar'. Even you can use pipe operator to do same thing, I have a similar code working on my AIX box without using ; which is command => 'gunzip /opt/splunkforwarder.tar.gz | tar -xvf-'. I hope this helps.

edit flag offensive delete link more

Comments

tar -zxvf not working on Solaris boxes. So using gunzip. Will try with your solution and get back to you. Thanks...!

rohithmn03 gravatar imagerohithmn03 ( 2017-06-15 05:06:08 -0500 )edit

used : gunzip /opt/splunkforwarder.tar.gz | tar -xvf- Getting tar: Unexpected end-of-file while reading from the storage media. error..! not worked for me.

rohithmn03 gravatar imagerohithmn03 ( 2017-06-15 21:45:28 -0500 )edit

This command worked fine..! gunzip --to-stdout /opt/splunkforwarder.tar.gz | tar -xvf -

rohithmn03 gravatar imagerohithmn03 ( 2017-06-15 21:47:02 -0500 )edit
0

answered 2017-06-20 12:53:21 -0500

jweierman gravatar image

I would also recommend reviewing the splunk module on the Forge here: https://forge.puppet.com/puppet/splunk It has recently been updated and should eliminate the need to run explicit exec commands to install the Splunk forwarder.

edit flag offensive delete link more
0

answered 2017-06-18 08:04:22 -0500

greynolds gravatar image

updated 2017-06-19 01:04:14 -0500

rajeevsharma gravatar image

Interesting! I generally use two exec commands with the meta-parameter "Before" to refer to the execution I want to run first. This way I can ensure there is not an over-step in execution.

exec {'unpack_splunk_forwarder.tar.gz':
        unless => 'test -f /opt/splunkforwarder/bin/splunk',
        cwd => '/opt',
        command => 'gunzip /opt/splunkforwarder.tar.gz ,
    }
exec { "untar":
        command => tar -xvf /opt/splunkforwarder.tar',
         path    => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:
  /usr/sbin:/usr/bin:/root/bin',
        onlyif  => '/bin/grep -c /opt /opt/ &splunkforwarder.tar.gz && exit 1 || exit 0',
         before  => Exec['unpack_splunk_forwarder.tar.gz"]
    }
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: 2017-06-15 02:23:29 -0500

Seen: 654 times

Last updated: Jun 19