Monday, 29 September 2014

shell script that will create unlimited virtual website on one single ip (Debian / Ubuntu)

Shell script that will create unlimited virtual website on one single ip on Debian/Ubuntu (There is another for  Red Hat , CentOs and Fedora.) 


#!/bin/bash
clear
echo "THIS SCRIPT IS  FOR PORT BASED APACHE VIRTUAL WEBSITES. MAKE UNLIMITED ON ONE SINGLE IP"
read -p  "We will run this script as root . press Enter to proceed..."
if [ $UID -eq 0 ]
then
echo "Lets see Apache is installed in your system or not...";sleep 2
apt-get install rpm 
rpm -q apache 1>/dev/null
if [ $? -eq 0 ]
then
echo "Apache present .  Now give me the port no you want to run your website on  ";  read q
echo "Setting up port for you...."; sleep 2
echo "Listen $q" >>  /etc/apache2/port.conf
echo "Creating $q root file..." sleep 2
echo "<VirtualHost *:$q>
        ServerAdmin webmaster@local
        DocumentRoot /var/www/html/$q
</VirtualHost>" > /etc/httpd/conf.d/"$q"
echo "Creating Document ...  " ; sleep 2
mkdir -p /var/www/html/$q
cd /var/www/html/$q
echo "Its $q, welcome to my website" > index.html
clear
echo "Your first website just built . If you want to make more website just do $0\nNow we will try to visit your wesite usig firefox" ;sleep 4
rpm -q firefox && firefox 127.0.0.1:$q || echo "firefox is not installed"
else
echo "Apache is not installed here  on your machine . type "apt-get install apache" to install."
fi
else
echo "You are not root . Try login as root  and do $0"
fi

Friday, 26 September 2014

shell script that will create unlimited virtual website on one single ip

Shell script that will create unlimited virtual website on one single ip on Red Hat , CentOs and Fedora. (There will be another for Ubuntu) 


#!/bin/bash
clear
echo "THIS SCRIPT IS  FOR PORT BASED APACHE VIRTUAL WEBSITES. MAKE UNLIMITED ON ONE SINGLE IP"
read -p  "We will run this script as root . press Enter to proceed..."
if [ $UID -eq 0 ]
then
echo "Lets see HTTPD is installed in your system or not...";sleep 2
rpm -q httpd 1>/dev/null
if [ $? -eq 0 ]
then
echo "HTTPD present .  Now give me the port no you want to run your website on  ";  read q
echo "Setting up port for you...."; sleep 2
echo "Listen $q" >>  /etc/httpd/conf/httpd.conf
semanage port -m -t http_port_t -p tcp $q
iptables -I INPUT -p tcp --dport $q -j ACCEPT
echo "Creating $q root file..." sleep 2
echo "<VirtualHost *:$q>
        ServerAdmin webmaster@local
        DocumentRoot /var/www/html/$q
</VirtualHost>" > /etc/httpd/conf.d/"$q"
echo "Creating Document ...  " ; sleep 2
mkdir -p /var/www/html/$q
cd /var/www/html/$q
echo "Its $q, welcome to my website" > index.html
clear
echo "Your first website just built . If you want to make more website just do $0\nNow we will try to visit your wesite usig firefox" ;sleep 4
rpm -q firefox && firefox 127.0.0.1:$q || echo "firefox is not installed"
else
echo "HTTPD is not installed here  on your machine . type "yum insatall httpd" to install."
fi
else
echo "You are not root . Try login as root  and do $0"
fi

Friday, 19 September 2014

Shell script that will create LVM of Maximum 3 partitions

echo "Writer::--Anuj Borah"
echo "Email::--anujborah1@gmail.com"





#!/bin/bash
clear

while true
do
clear
echo "This script will create LVM of Maximum 3 partitions"
echo "Writer::Anuj Borah"
echo "Email::anujborah1@gmail.com"
echo -e "You have Following configuration:\n`sudo fdisk -l | grep /dev `\n\nHow many partitions you wana use for LVM give us the no Ex: 1 or 2 or 3  "
read q
if [ $q -eq 1 ]
then
echo "OK.Enter the name of $q partition"
read r
sudo fdisk -l | grep $r 1>/dev/null 
if [ $? -eq 0 ]
then
echo -e "$r present" ; echo "$r  is the  partition will be used to create LVM ";read -p "Press "Enter" to continue....."; echo "Creating PV...." ;`sudo pvcreate $r 2>/dev/null`;sleep 2;echo "Creating VG..."`sudo vgcreate vg $r 2>/dev/null`;sleep 1;echo "Creating LV...";echo "Give us what will be size of LV in MB: ";read q; `sudo lvcreate -L"$q"M  vg 2>/dev/null`;sleep 3;echo "mounting LV at /media/usb";`sudo mkdir /media/usb 2>/dev/null`;`sudo mkfs.ext4 /dev/vg/lvol0 2>/dev/null`;sleep 10;`sudo mount /dev/vg/lvol0 /media/usb`;echo -e "All done\nyour current LVM:::--- `df -h | grep /media/usb`"
else
echo "$r does not exists" 
break
fi
elif [ $q -eq 2 ]
then
echo "OK.Enter the name of $q partition"
read r e
sudo fdisk -l | grep $r 1>/dev/null
if [ $? -eq 0  ]
then 
echo "$r present "
else 
echo "$r does not exists"
break
fi
sudo fdisk -l | grep $e 1>/dev/null
if [ $? -eq 0  ]
then 
echo "$e present "
else 
echo "$e does not exists"
break
fi
read -p "$e , $r are two partitions will be used to create LVM. Press "Enter" to proceed...";echo "Creating PV...." ;`sudo pvcreate $r $e 2>/dev/null`;sleep 2;sudo pvs;sleep 2;echo "Creating VG..."`sudo vgcreate vg $r 2>/dev/null`;sleep 2;sudo vgs ; sleep 2;echo "Creating LV...";echo "Give us what will be size of LV in MB: ";read q; `sudo lvcreate -L"$q"M  vg`2>/dev/null;sleep 3;sudo lvs;sleep 2;echo "mounting LV at /media/usb";`sudo mkdir /media/usb 2>/dev/null`;`sudo mkfs.ext4 /dev/vg/lvol0 2>/dev/null`;sleep 10;`sudo mount /dev/vg/lvol0 /media/usb 2>/dev/null `;echo -e "\nAll done\nyour current LVM:::--- `df -h | grep /media/usb`"
break
elif [ $q -eq 3 ]
then
echo "OK.Enter the name of $q partition"
read r e t
sudo fdisk -l | grep $r 1>/dev/null
if [ $? -eq 0  ]
then 
echo "$r present "
else 
echo "$r does not exists"
break
fi
sudo fdisk -l | grep $e 1>/dev/null
if [ $? -eq 0  ]
then 
echo "$e present "
else 
echo "$e does not exists"
break
fi
sudo fdisk -l | grep $t 1>/dev/null
if [ $? -eq 0  ]
then 
echo "$t present "
else 
echo "$t does not exists"
break
read -p "$e , $r , $t are three partitions will be used to create LVM. Press "Enter" to proceed...";echo "Creating PV...." ;`sudo pvcreate $r $e $t 2>/dev/null`;sleep 2;sudo pvs;sleep 2;echo "Creating VG..."`sudo vgcreate vg $r 2>/dev/null`;sleep 2;sudo vgs ; sleep 2;echo "Creating LV...";echo "Give us what will be size of LV in MB: ";read q; `sudo lvcreate -L"$q"M  vg 2>/dev/null`;sleep 3;sudo lvs;sleep 2;echo "mounting LV at /media/usb";`sudo mkdir /media/usb 2>/dev/null`;`sudo mkfs.ext4 /dev/vg/lvol0 2>/dev/null`;sleep 10;`sudo mount /dev/vg/lvol0 /media/usb 2>/dev/null `;echo -e "\nAll done\nyour current LVM:::--- `df -h | grep /media/usb`"
break
fi
fi
done

Friday, 12 September 2014

Script that will first check usb is attached to your system or not then automatically copy the file or dir to external usb attached to your pc . user will give the input.

Script that will first check usb is attached to your system or not then automatically copy the file or dir to external usb attached to your pc . user will give the input.

Writer: Anuj Borah
email: anujborah1@gmail.com


#!/bin/bash
clear
read -p "First i will see how much usb is attached to your system: Press ENTER to continue.... "
echo "`sudo fdisk -l | grep "/dev/*" | grep -i "GB\|MB" | wc -l` no of disk attached to your pc"
echo "`sudo fdisk -l | grep "/dev/*" | grep -i "MB" | wc -l ` of usb is auttached currently named:"
a=`sudo fdisk -l | grep "/dev/*" | grep -i "MB" | wc -l`
if [ $a -eq 1 ]
then
sudo fdisk -l | grep "/dev/*" | tail -1 | cut -c-10

echo "Please provide me the file that you want to copy to usb "
read a
if [ -d $a ] || [ -a $a ]
then
b=`sudo fdisk -l | grep "/dev/*" | tail -1 | cut -c-10`
echo "ok file/dir present . i will copy ur $a file/dir to $b. press y to presed "
read v
if [ $v = "y" ]
then
echo "ok "
sudo mkdir /media/usb1 2>/dev/null
sudo umount  /media/* 2>/dev/null
sudo mount $b /media/usb1
sudo cp -v $a /media/usb1
clear
echo "+++++++++++++++++++++()All Done()+++++++++++++++++++++++++"
else
echo "You did not pressed y . i am quting start from beginig"
fi
else
echo "the file or dir does not exit "
fi
elif [ $a -eq 2 ]
then
sudo fdisk -l | grep "/dev/*" | tail -2 | cut -c-10
echo "Please provide me the file that you want to copy to usb "
read a
if [ -d $a ] || [ -a $a ]
then
b=`sudo fdisk -l | grep "/dev/*" | tail -1 | cut -c-10`
echo "ok file/dir present . i will copy ur $a file/dir to $b. press y to presed "
read v
if [ $v = "y" ]
then
echo "ok "
sudo mkdir /media/usb1 2>/dev/null
sudo umount  /media/* 2>/dev/null
sudo mount $b /media/usb1
sudo cp -v $a /media/usb1
clear
echo "+++++++++++++++++++++()All Done()+++++++++++++++++++++++++"
else
echo "You did not pressed y . i am quting start from beginig"
fi
else
echo "the file or dir does not exit "
fi

elif [ $a -eq 3 ]
then
sudo fdisk -l | grep "/dev/*" | tail -3 | cut -c-10
echo "Please provide me the file that you want to copy to usb "
read a
if [ -d $a ] || [ -a $a ]
then
b=`sudo fdisk -l | grep "/dev/*" | tail -1 | cut -c-10`
echo "ok file/dir present . i will copy ur $a file/dir to $b. press y to presed "
read v
if [ $v = "y" ]
then
echo "ok "
sudo mkdir /media/usb1 2>/dev/null
sudo umount  /media/* 2>/dev/null
sudo mount $b /media/usb1
sudo cp -v $a /media/usb1
clear
echo "+++++++++++++++++++++()All Done()+++++++++++++++++++++++++"
else
echo "You did not pressed y . i am quting start from beginig"
fi
else
echo "the file or dir does not exit "
fi

else
echo "no usb attached. Please insert usb to perform the copy task"
fi





   

Thursday, 11 September 2014

Script to detect how many pen drives are attached to your system



#!/bin/bash
clear
echo "`sudo fdisk -l | grep "/dev/*" | grep -i "GB\|MB" | wc -l` no of disk attached to your pc"
echo "`sudo fdisk -l | grep "/dev/*" | grep -i "MB" | wc -l ` of usb is auttached currently named:"
a=`sudo fdisk -l | grep "/dev/*" | grep -i "MB" | wc -l`
if [ $a -eq 1 ]
then
sudo fdisk -l | grep "/dev/*" | tail -1 | cut -c-10
elif [ $a -eq 2 ]
then
sudo fdisk -l | grep "/dev/*" | tail -2 | cut -c-10
elif [ $a -eq 3 ]
then
sudo fdisk -l | grep "/dev/*" | tail -3 | cut -c-10
else
echo no usb attached.
fi

Wednesday, 10 September 2014

Create a script that will take a (recursive) copy of files in /etc so that a beginning system administrator can edit files without fear.

Q:Create a script that will take a (recursive) copy of files in /etc so that a beginning system administrator can edit files without fear.


Ans By: Anuj Borah
Email: anujborah1@gmail.com

#!/bin/bash
clear
echo "This script will make extra copy of each directory and file"
echo "Give the directory like:/home/user/Desktop/anuj"
read a
cd $a 2>/dev/null
test -d $a 2>/dev/null
if [ $? -eq 0 ]
then
echo "$a Dir exists"
a=`ls -l|grep "^d" | cut -c47- | wc -l`
echo "$a dir found. You wana proced for dir section ? pess y "
read a
if [ $a == "y" ]
then
a1=`ls -l|grep "^d" | cut -c47-`
for i in $a1
do
sudo cp -rv "$i" "$i".original 2>/dev/null
done
echo "all done for dir portion . now we will copy files .  press y to pressed"
read a
if [ $a == "y" ]
then
b=`ls -l|grep "^-" | cut -c47- | wc -l`
echo "$b file are present"
b1=`ls -l|grep "^-" | cut -c47-`
for i in $b1
do
sudo cp -rv "$i" "$i".original 2>/dev/null
done
echo "all done Thanks"
else
echo "As u did not pressed y so we will quit . Start from begining press $0"
fi
else
echo "As u did not pressed y so we will quit .But all directries are coppied. Start from begining press $0"
fi
else
echo "No $a such dir " 
fi










Monday, 8 September 2014

Script1: Take user input and calculate Total size occupied by .

#!/bin/bash
clear
if [ $# -ne 0 ]
then
echo no argument needed.
else
echo "enter the directory or file location u want to see disk space"
read a
test -d $a
if [ $? -eq 0 ]
then
echo  "total space required will be aproximate:`du -h $a > 11 2>&1; tail -1 11 | cut -c-4`  "
fi
fi


Popular Posts