I have borrowed below code from the google and modified it a little but somehow it not giving the expected output.
Shell function:
remote_collect() {
target_host=$1
{
read -r rhelInfo
read -r perlInfo
} < <(
ssh -i my_connect "root@${target_host}" \
-o StrictHostKeyChecking=no -o PasswordAuthentication=no \
/bin/bash <<-EOF
cat /etc/redhat-release | awk 'END{print \$7}'
#rpm -qa --last | awk '/kernel-[0-9]/'|head -1
rpm -qa --last | awk '/kernel-[0-9]/{ first=$1; $1=""; print $0 }'
EOF
) 2>/dev/null
Where is Problem:
In the above function the command rpm -qa --last | awk '/kernel-[0-9]/{ first=$1; $1=""; print $0 }'
does not produce anything while running as an script however if i use rpm -qa --last | awk '/kernel-[0-9]/'|head -1
then this works perfectly, So, where i am missing something like escaping something?
Please help to make me understand or resolve this.
CodePudding user response:
You should escape all the $
sequence in Order to work, and it should work.
Please try below.
rpm -qa --last | awk '/kernel-[0-9]/{ first=\$1; \$1=""; print \$0 }'