Error executing action run on resource ‘execute[Check if package is available]’ Mixlib::ShellOut::ShellCommandFailed

hi,
I’m trying to run a piped Linux command by creating the script zypper_script.sh in /tmp folder. The command i’m using is
zypper search -s kernel | grep -P ‘(^|\s)\Kkernel-default-devel(?=\s|)’ | grep (rpm -qa | grep kernel-default-[0-9] | sort -Vr | head -1 | cut -c 16- | awk ‘{print substr($0, 1, length($0)-7)}’) > /tmp/package-info

This will give info regarding the package available in the file /tmp/package-info.
But while executing the script using the execute resource, i’m getting the below error.

Error executing action run on resource ‘execute[Check if package is available]’
Mixlib::ShellOut::ShellCommandFailed
Expected process to exit with [0], but received ‘1’
---- Begin output of sh /tmp/zypper_script.sh ----
STDOUT:
STDERR:
---- End output of sh /tmp/zypper_script.sh ----
Ran sh /tmp/zypper_script.sh returned 1

Resource Declaration:
execute “Check if package is available” do
command "sh /tmp/zypper_script.sh"
end
Kindly help me ASAP to resolve the issue. Thanks

This seems like a problem with the script itself - Chef is just relaying the message that when it tries to run that script it is receiving an error. Try running that script manually and checking the exit code. Also consider that chef-client is running as root and might have different env settings or binaries available in the path.