root@srv [~]# cat /etc/redhat-release | awk {'print $1}'
Red
root@srv [~]# cat 123.sh
if (( `cat /etc/redhat-release | awk {'print $1}'` != CentOS )); then { echo "System runs on Redhat Linux. Exiting..."; exit; } fi
root@srv [~]# sh 123.sh
root@srv [~]#
root@srv [~]# if (( `cat /etc/redhat-release | awk {'print $1}'` != CentOS )); then { echo "System runs on Redhat Linux. Exiting..."; exit; } fi
root@srv [~]#
root@srv [~]# sh -x 123.sh
++ cat /etc/redhat-release
++ awk '{print $1}'
+ (( Red != CentOS ))
root@srv [~]#
Please advise or provide a alternative so that I can include it in a shell script that will use up2date, in case it is RHEL ( i am aware RHEL 5 use yum ) and will use yum incase it is CentOS
If /etc/redhat-release doesnot exit , echo system not running redhat or CentOS or redhat-release file is missing, then do nothing below, if /etc/redhat-release exists , then find the OS flavour and,
## if system is Redhat
OS=`cat /etc/redhat-release | awk {'print $1}'`
if [ "$OS" != "CentOS" ]
then
echo "System runs on Redhat Linux.";
do
up2date -i ncurses dialog nmap
done
exit;
fi
## if system is Centos
echo "System runs on CentOS.";
do
yum -y install ncurses dialog nmap
done
I can run the above script two times and one of them will do the install, yum or up2date. I will look better , if we use the value ( Red or CentOS ) and then build a script like ( nested or whatever you call )
If /etc/redhat-release doesnot exit , echo system not running redhat or CentOS or redhat-release file is missing, then do nothing below
else
OS=`cat /etc/redhat-release | awk {'print $1}'`
if [ "$OS" != "CentOS" ]
then
echo "System runs on Redhat Linux.";
then use the up2date command
else if system runs Centos
then use the yum comand
done
root@server2 [~]# cat /proc/version
Linux version 2.6.9-42.0.3.ELsmp (buildsvn@build-i386) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)) #1 SMP Fri Oct 6 06:21:39 CDT 2006
root@server2 [~]#
Back to the original issue, in case we know that we are using either Redhat ( RHEL 4 or < ) Or CentOS , then the following script seems should do the trick.
=============================
OS=`cat /etc/redhat-release | awk {'print $1}'`
if [ "$OS" != "CentOS" ]
then
up2date -i dialog nmap ncurses ;
else
yum install -y dialog nmap ncurses
fi