I have a little script in bash which checks if the server is a cPanel server
#!/bin/bash
echo "checking"
x=$(/usr/local/cpanel/cpanel -V)
if [ "$x" ]; then
echo "yes"
else
echo "no"
fi
This works fine and gives the correct expected output. However, when run on non-cPanel servers, it also throws the following error:
./testcpanel.sh: line 2: /usr/local/cpanel/cpanel: No such file or directory
I would like to suppress this output.
I tried inserting 2>&1 /dev/null
in the variable declaration but that doesn't work. It always gives yes
as the output irrespective of whether cPanel exists on not.
how do I go about suppressing the output? (OS's tested on - CentOS 6 and Ubuntu 13.04)