Hi Vadim,
I used following:
(the $string uses <double><single> .... <single><double> quotes
[johan@zbook ~]$ cat test.pp
$string = "'a quoted string'"
exec { 'show string':
command => "echo \"I want to see ${string}\"",
logoutput => true,
path => '/bin:/usr/bin',
}
[johan@zbook ~]$ puppet apply test.pp
Notice: Compiled catalog for zbook.koewacht.net in environment production in 0.06 seconds
Notice: /Stage[main]/Main/Exec[show string]/returns: I want to see 'a quoted string'
Notice: /Stage[main]/Main/Exec[show string]/returns: executed successfully
Notice: Applied catalog in 0.06 seconds
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/923ff9af-4321-4dee-a7b9-8002a1204042%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi,I can't figure out how to include a single quoted string into a command, not matter what escaping I do.Here is a simplified code :$string = '\'a quoted string\''exec { 'show string':command => "echo \'I want to see ${string}\'",logoutput => true,path => '/bin:/usr/bin',}Quotes don't show up, no matter what.What do I do wrong?
echo 'I want to see 'a quoted string''
echo "I want to see a" quoted string
I want to see a quoted string
There are several ways to go about what you are after but the bottom line is that you need to recognize that the strings will be processed at least twice: once by Puppet, and once by Kernel.exec(), in that order. You need to insert appropriate escapes or quotes into your command for the latter, and then escape or quote the result for the former.
$string = "\\'a quoted string\\'"
exec { 'show string':
command => "echo I want to see ${string}",
logoutput => true,
path => '/bin:/usr/bin',
} $sig_command = "'kill -HUP `cat /var/run/syslog.pid`'"
/usr/bin/echo "# local0 rotation rule
local0.log -C 5 -a 'kill -HUP `cat /var/run/syslog.pid`' -p 1d" >> /etc/logadm.conf
Shell allows me to escape back-tick:$ echo "/var/log/syslog -C 8 -a 'kill -HUP \`cat /var/run/syslog.pid\`'"/var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/syslog.pid`'puppet does like them:$string="/var/log/syslog -C 8 -a 'kill -HUP \`cat /var/run/syslog.pid\`'"
exec{'echo string':command => "echo \" ${string} \" ",logoutput => true,path => '/bin:/usr/bin',}Warning: Unrecognised escape sequence '\`' in file /home/vc7733/quotes.pp at line 1Warning: Unrecognised escape sequence '\`' in file /home/vc7733/quotes.pp at line 1Notice: Compiled catalog for pubdevx-dev601.bnaint.com in environment production in 0.36 secondsNotice: /Stage[main]/Main/Exec[echo string]/returns: /var/log/syslog -C 8 -a 'kill -HUP `cat /var/run/syslog.pid`'And as I said earlier, no, I can't use file_lineThanks,Vadym
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/aee7a6c5-307f-4b55-87ac-85f205724ff4%40googlegroups.com.
Puppet is interpreting \` as an escape sequence since it's in a double-quoted string, and reporting that it's an invalid escape sequence. I think you'll need to escape the backslash:$string="/var/log/syslog -C 8 -a 'kill -HUP \\`cat /var/run/syslog.pid\\`'"