I am new to shell script, I created a sh file and it works well on the terminal, see the code below:
#!/bin/bash
# Use dmidecode to get version
dmidecode=`dmidecode -t chassis | grep 'Version' | sed -r 's/.*(.{6})/\1/'`
# Use ipmitool to get version
fru=`ipmitool fru | grep 'Chassis Part Number' | sed -r 's/.*(.{6})/\1/'`
# Compare the result
compare_result=0
if [ "$dmidecode" == "$fru" ]; then
compare_result="pass"
else
compare_result="false"
fi
# Create json
printf '"tcresult": {"dmidecode":{"chassis_type":"%s"},"fru":{"chassis_type":"%s"},"compare_result":"%s"}\n' "$dmidecode" "$fru" "$compare_result"
And the outcome is:
"tcresult": {"dmidecode":{"chassis_type":"N42.12"},"fru":{"chassis_type":"N42.12"},"compare_result":"pass"}
However, when I execute the sh file, the error shows below:
[root@localhost ~]# cd Desktop/
[root@localhost Desktop]# ls
avms avms.tar check_chasis.sh
[root@localhost Desktop]# sh check_chasis.sh
: command not foundne 3:
: command not foundne 7:
check_chasis.sh: line 15: syntax error: unexpected end of file
Thanks in advance for any advise or comment. Also see screenshot below