Reputation: 60
I am writing a recipe in chef in which I have used script resource with bash interpreter to execute sed command :
script 'find the lastest version of the major release available' do
interpreter "bash"
code <<-EOH
SUBMGR_REPO=$(ls -1d /net/gutstools.am.lilly.com/guts_dev/distr/redhat/* | egrep `echo as6-u7_64 | sed -r 's/([aw]s[[:digit:]]+).*$/\1-u[[:digit:]]+(_64)?$/'` 2>/dev/null | sort -nr -t/ -k 7.6,7 | awk -F/ '{ print $7 }' | head -1)
echo $SUBMGR_REPO
EOH
end
If I run above command from terminal it works fine as follows:
[c244728_lx@brainiac-ia-0008 redhat]$ SUBMGR_REPO=$(ls -1d /net/gutstools.am.lilly.com/guts_dev/distr/redhat/* | egrep `echo as6-u7_64 | sed -r 's/([aw]s[[:digit:]]+).*$/\1-u[[:digit:]]+(_64)?$/'` 2>/dev/null | sort -nr -t/ -k 7.6,7 | awk -F/ '{ print $7 }' | head -1)
[c244728_lx@brainiac-ia-0008 redhat]$ echo $SUBMGR_REPO
as6-u8_64
[c244728_lx@brainiac-ia-0008 redhat]$ ls
as5-u10_64 as5-u8_64 as6-u4_64 as6-u5_64.tar as7-u1_64 ws5-u10 ws5-u6_64 ws5-u9 ws6-u2_64 ws6-u5 ws6-u7_64
as5-u11_64 as5-u9_64 as6-u5_64 as6-u6_64 as7-u2_64 ws5-u10_64 ws5-u7 ws5-u9_64 ws6-u3 ws6-u5_64 ws6-u8_64
as5-u5_64 as6-u1_64 as6-u5_64_1 as6-u7_64 krb5-patch ws5-u11 ws5-u7_64 ws6-u1 ws6-u3_64 ws6-u6 ws7-u1_64
as5-u6_64 as6-u2_64 as6-u5_64-GBIP as6-u7_64-GBIP openssl.tar ws5-u11_64 ws5-u8 ws6-u1_64 ws6-u4 ws6-u6_64 ws7-u2_64
as5-u7_64 as6-u3_64 as6-u5_64-kernel-patch as6-u8_64 ruby22_rail41_CHG0053697 ws5-u6 ws5-u8_64 ws6-u2 ws6-u4_64 ws6-u7
[c244728_lx@brainiac-ia-0008 redhat]$
But fails in chef recipe, it gives null value in $SUBMGR_REPO. Please help me to solve this.
Thanks.
Upvotes: 0
Views: 125
Reputation: 54251
You should really consider refactoring this a bit but I would bet the issue is you have some unescaped backslashes that need fixing (e.g. \\1
)
Upvotes: 1