Linux script for rpm -qa --last output - help with the linux command

I am trying to execute the following command to output installed RPM.

#!/bin/bash
/usr/bin/rpm -qa --last > /opt/BESClient/bin/installedpatch/installedpatch.csv

However when I run this either of the BigFix actions below , the scripts will process all lines with completed including creating the file which is empty however it returns a exit code of 127. I think the problem is that I must not be setting the path correctly as I have to manually cd to /usr/ and then cd /bin/ to run the command .

Any help with the linux command to fix this would be great

Script 1
// Enter your action script here
//ADD CODE HERE TO CREATE “OPEN SOURCE SOFTWARE” FILES.
delete __appendfile
if {name of operating system contains “inux”}
appendfile #!/bin/bash
appendfile /usr/bin/rpm -qa --last > /opt/BESClient/bin/installedpatch/installedpatch.csv
delete "install.sh"
delete /opt/BESClient/bin/installedpatch/installedpatch.csv
move __appendfile "install.sh"
wait chmod +x install.sh
wait ./install.sh
endif

Script 2

// Enter your action script here
if {name of operating system contains “inux”}
delete "/opt/BESClient/bin/installedpatch/installedpatch.csv"
wait sh -c "/usr/bin/rpm -qa --last >> /opt/BESClient/bin/installedpatch/installedpatch.csv"
endif