have the following code
#!/bin/bash
#testing script
#commands
server= $(hostname)
cmd1= "$(cat /etc/system-release | grep "7." | wc -l)"
cmd2= "$(cat /etc/system-release | grep "6." | wc -l)"
#creatingFunction
function os_check(){
echo "#######-OS_Checker-#######"
echo "The VM $server is running on: "
if [ "$cmd1" -ne 0 ]; then
echo "Centos 7"
elif [ "$cmd2" -ne 0 ]; then
echo "Centos 6"
else
echo "Something went wrong"
fi
echo "##########################"
}
#running function
os_check
but it's given me the following errors:
user@server-name:[~]:$ ./checking.sh
./checking.sh: line 5: server-name: command not found
./checking.sh: line 6: 1: command not found
./checking.sh: line 7: 0: command not found
#######-OS_Checker-#######
The VM is running on:
./checking.sh: line 13: [: : integer expression expected
./checking.sh: line 15: [: : integer expression expected
Something went wrong
##########################
basically am doing a count to check if is centos 6 or 7, but not able to determinate why doesn't work properly on the script, any advise will be appreciated!
command example:
user@server-name:[~]:$ cat /etc/system-release | grep "7." | wc -l
1
user@server-name:[~]:$ cat /etc/system-release | grep "6." | wc -l
0