#!/bin/bash
#Variables
num1=10
num2=20
num3=$((num1+1))
#Functions
#function for arithmetic addition
function add
{
echo "into add function"
echo "sum = $((num1+num2))"
echo "third number = $num3"
return
}
#function for system information
function system_info
{
echo -e "\n Hostname: $HOSTNAME \n User: $USER \n Uptime: uptime"
echo -e "\n Disk Space: \n $(df -h)"
echo -e "\n ps auxf: \n $(ps auxf)"
echo -e "\n Press Enter button to see top -c output or press ctrl+c to exit"
read blackhole
top
}
#function for version information : incomplete
#function version_information_incomplete
#{
#echo -e "\n php version: $(php -v) \n mysql version: command not added yet \n $(cat /proc/version)"
#echo -e "\n"
#php -v
#echo -e "\n"
#echo -e "add mysql command in script file \n"
#echo -e "kernel version: \n"
#cat /proc/version
#}
#function for version information : Specs needed by sales
function version_info
{
echo -e "Operating system : \t $(cat /etc/redhat-release)"
echo -e "Kernel version : \t $(uname -r)"
echo -e "Apache version : \n $(httpd -v)"
echo -e "PERL version : \t $(perl -vi)"
echo -e "PHP version : \t $(php -v)"
echo -e "MySQL version : \t $(mysql -V)"
echo -e "Exim Mail Server version :\t $(exim -bV)"
echo -e "cPanel Build(Unchecked command) : \t $(cpanel -V)"
}
#function to check conditional statements(example, if)
function condition
{
echo -e "\n Enter option number : \n 1.To check load \n 2.To check disk space \n"
read option
echo $option
if [ "$option" = "1" ]; then
w
elif [ "$option" = "2" ]; then
df -h
else
echo "\n wrong option"
fi
}
#fuction for testing purpose
function test
{
if [ "$(id -u)" = "0" ]; then
echo "<h2>Home directory space by user</h2>"
echo "<pre>"
echo "Bytes Directory"
du -s /home/* | sort -nr
echo "</pre>"
fi
}
#function for case statement : not working properly
function case_condition
{
echo -n "Enter a number"
read digit
case $digit in
[0-9] ) echo "below ten"
;;
[10-19] ) echo "between 10 to 19"
;;
* ) echo "invalid option"
esac
}
#function for commandline addition using parameters: Caution function will not work when nested.
function commandline_add
{
a=$1
b=$2
echo $a $b
c=$((a+b))
echo $c
}
#function for for loop:
function for_loop
{
for i in un dos tres; do
echo $i
done
}
#Main
#add
#system_info
#version_info
#condition
#test
#case
case_condition
#commandline_add
#for_loop
trap for_loop