Puppet read output of command and store in a variable

8,006

Use this

command => "/bin/cp \"`/usr/bin/head -1 /tmp/testfile.out | cut -d\",\" -f2`\"/application/myscript.sh /var/tmp/myscript.sh",
creates => "/var/tmp/myscript.sh"

It works for me ..

Share:
8,006

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I am very new to puppet and trying to execute my puppet script but its failing all the time.

    I want to store the output of below bash command and want to store in a variable which I can use later:

    /usr/bin/head -1 /tmp/testfile.out | cut -d',' -f2'3
    

    Which I am passing to my puppet script to read a file from another location

    variable => generate('/usr/bin/head -1 /tmp/testfile.out | cut -d',' -f2'),
    command => "/bin/cp /${variable}/application/myscript.sh /var/tmp/myscript.sh",
    creates => "/var/tmp/myscript.sh",
    

    But when I execute this puppet script it fails. I am not sure even if above one is correct too. Any help would be appreciated.

    Thanks

    EDITED

    testfile.out contains a cron data which is generated using my custom php script in that I have application name on the first line of the file. Sample entry of the file :

    cat testfile.out
    server.amazon.com,zimbra,1080,3000
    

    I have a script which sits on a nfs share which starts with the application name $variable and I need to copy on that server which will run check for all zimbra related files and folders. Even I am not sure about this script what it does exactly as its a binary file..

    • Florin Asăvoaie
      Florin Asăvoaie over 9 years
      First of all you have syntax errors. You need to escape the "'"s before and after the comma.
    • Admin
      Admin over 9 years
      @FlorinAsavoaie: Which line you are referring too.. If I do not use variable part in that puppet script it works so I am not sure what you are referring too.
    • faker
      faker over 9 years
      The single quotes at cut -d ',' need to be escaped.
    • Pratap
      Pratap over 9 years
      Try replacing the $variable with actual syntax
    • faker
      faker over 9 years
      You can probably work around this by deploying a shell script which executes this command. But: can you please explain better what you are trying to do? You know that generate runs on the master server, not the node, right?
    • Admin
      Admin over 9 years
      @faker Yes I am learning about generate.. thanks, what is the best way to use variable in puppet as I will be using this script across multiple servers and those will be client nodes so generate will fail. I am editing my question as you have requested. @PratapSingh: That does not help either ..
    • Zoredache
      Zoredache over 9 years
      Add facts, that is extend facter.
    • Admin
      Admin over 9 years
      I am not sure how to use facts but checking it . Thanks @Zoredache