Puppet read output of command and store in a variable
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 ..
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
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 over 9 yearsFirst of all you have syntax errors. You need to escape the "'"s before and after the comma.
-
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 over 9 yearsThe single quotes at
cut -d ','
need to be escaped. -
Pratap over 9 yearsTry replacing the $variable with actual syntax
-
faker over 9 yearsYou 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 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 over 9 yearsAdd facts, that is extend facter.
-
Admin over 9 yearsI am not sure how to use facts but checking it . Thanks @Zoredache
-