Sunday, 28 December 2014

script to install flash player on CentOS, Fedora, RedHat

script to install  flash player on CentOS, Fedora, RedHat


Writer: Anuj Borah
Email: anujborah1@gmail.com

#!/bin/bash
clear
if [ $UID -eq 0 ]
then
echo "Downloading the necessary file ....  wait"
sleep 3
wget "http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.425/install_flash_player_11_linux.x86_64.tar.gz"

clear
tar -zxvf install_flash_player_11_linux.x86_64.tar.gz

clear
cp libflashplayer.so /usr/lib64/mozilla/plugins/ > /dev/null
cp -r usr/* /us > /dev/null
echo "Configuration on the way... have patient..."

sleep 3

clear
echo "All Done , Restart firefox now ."

else
echo "&&&&&&This Script will run as root only ,  login as root and try $0  again. &&&&&&"
fi

Script to mount ntfs drives on Red Hat , CentOs And Fedora.

 Script to mount ntfs drives on Red Hat , CentOs   And Fedora.

Writter:Anuj Borah
Email: anujborah@gmail..com



#!/bin/bash
clear
echo -e "Wecome\nWriter:Anuj Borah\nEmail:anujborah1@gmail.com"
sleep 3
if [ $UID -eq 0 ]
then
rpm -q gcc &&  echo "OK Nice" || echo "gcc not installed u must install  gcc type 'yum install gcc' then try again"
sleep 3
wget "tuxera.com/opensource/ntfs-3g_ntfsprogs-2014.2.15.tgz"
clear
echo "Download in progress , wait "
sleep 3
tar -zxvf ntfs-3g_ntfsprogs-2014.2.15.tgz
cd ntfs-3g_ntfsprogs-2014.2.15
clear
chmod +x *
clear
./configure
make
make install
clear
echo "Looks like every thing gone fine.Now i will check it"
firefox borahshell.blogsopt.in
sleep 3
clear
echo "give me the drive to mount to your system"
read p
clear
echo "Given drive $p and the drive will be mounted to /media/usb"
sleep 3
clear
mkdir /media/usb >/dev/null
mount mount -t ntfs-3g $p  /media/usb
clear
echo "Congrats all done . Now u can access ntfs drive by typing cd /media/usb"
else
echo "&&&&&&This Script will run as root only ,  login as root and try $0  again. &&&&&&"
fi


Tuesday, 23 December 2014

Shell script that will allow live monitoring of Apache Server

This the script that will enable live monitoring of Apache Server Ex. Who is currently logged on to it.

It will be look like the following screen shot .



Note: This script will work for Ubuntu (All  versions) and Debian(All Version ) only. There is another script for Redhat , Centos and Fedora.


Writer: Anuj Borah
Email: anujborah1@gmail.com



#!/bin/bash
clear
Writer: Anuj Borah
Email: anujborah1@gmail.com
sleep 3
echo "This the script for apache server monitoring.(Press F5 to refress)"
sleep 3
if [ $UID -eq 0 ]
then
dpkg -l apache2 && echo "Congrats ,Apache is installed" || echo "Apache is not installed type (apt-get install apache2) to linstall apache"
sleep 3
a2enmod status > /dev/null
clear
echo "Give the ip address to which u want to associate for apache server monitoring " ; read p

echo "<IfModule mod_status.c>
    # Allow server status reports generated by mod_status,
    # with the URL of http://servername/server-status
    # Uncomment and change the "192.0.2.0/24" to allow access from other hosts.

    <Location /server-status>
        SetHandler server-status
        Require local
        Allow from 127.0.0.1 ::1 $p
        #Require ip 192.0.2.0/24
    </Location>

    # Keep track of extended status information for each request
    ExtendedStatus On

    # Determine if mod_status displays the first 63 characters of a request or
    # the last 63, assuming the request itself is greater than 63 chars.
    # Default: Off
    #SeeRequestTail On


    <IfModule mod_proxy.c>
        # Show Proxy LoadBalancer status in mod_status
        ProxyStatus On
    </IfModule>


</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet" > /etc/apache2/mods-enabled/status.conf

service apache2 restart > /dev/null

clear
echo "All Done. Now i will enable the system.(Press F5 to refress) "
sleep 3
firefox http://127.0.0.1:server-status

else
echo "&&&&&&This Script will run as root only ,  login as root and try $0  again. &&&&&&"
fi

Tuesday, 11 November 2014

script for interview perpose

Write a bash​ shell​ or perl script which does the following:

 - accepts a syslog file path, comma seperated list of service names and another argument which is a string (​this is an optional argument)
 - prints the count of logs of each service name on a separate line
 - If the optional string argument is provided, then searches for it in the logs of the provided service names and prints its count ​on a separate line.
 - prints usage if it is incorrect

 This was interview question for me .  Look how i have given the solution after 3 attempt :)



 Writer: Anuj Borah
Email: anujborah1@gmail.com



#!/bin/bash
clear
 echo -e "__________ Welcome____________\n"
if [ $# -eq 0 ]; then
echo "Please provide the ./script-name, file name and service-name (ex- ./script syslog CRON,CRON... critical )  "
fi
if [ $# -eq 2 ]; then
test -f $1
if [ $? -eq 0 ]
then
a=$1
oIFS="$IFS"; IFS=, ; set -- $2 ; IFS="$oIFS"
for i in "$@"; do
echo $i has the following count:
grep -o $i $a | wc -l
grep $i $a >> /tmp/1
done
fi
elif [ $# -eq 3 ]; then
echo -e "$1\n$2\n$3" >> /tmp/2
a=$1
oIFS="$IFS"; IFS=, ; set -- $2 ; IFS="$oIFS"
for i in "$@"; do
echo $i has the following count:
grep -o $i $a | wc -l
grep $i $a >> /tmp/1
done

b=`awk 'NR==3' /tmp/2`
echo  -e "\nThe over all count for $b is as follows:"
grep $b /tmp/1 | wc -l || echo "No such word" && echo "All Done"
rm /tmp/1 > /dev/null
rm /tmp/2 > /dev/null
else
echo "No such file"
fi



See the output



Wednesday, 29 October 2014

Script that will act as a converter in linux





Script that will convert mp3 to ogg ,  ogg to mp3 ,  mp4 to mp3 etc

### How to play music in Red-hat , Fedora,  Cent-Os ,  Debian,  Ubuntu with out installing player like vlc or any third party software .


Writer: Anuj Borah
Email : anujborah1@gmail.com


#!/bin/bash
clear
echo "This script will convert files )like mp3 to ogg or mp4 to ogg("
echo "Now Give me the folder location where the input files are present 9 )Ex- /home/anuj/Desktop("
read t
test -d $t
if [ $? -eq 0 ]
then
echo "$t is present."
cd $t
read -p "Give me input file format and output file format ...." q e

for file in *.$q;

   do ffmpeg -i "${file}" -acodec libvorbis "${file%q}.$e";

done
clear
echo "ALL Done .  Your outputs are `ls -l *.$e` "
else
clear
echo "No such $t folder. Try Again "
fi



Tuesday, 21 October 2014

shell script that will mange your user and groups in debian/ ubuntu system


 ###shell  script that will mange your user and groups in debian/ ubuntu system



writer: anuj borah
email: anujborah1@gmail.com




#!/bin/bash
clear
echo "*******************Script that will make manage user and groups for you ************************** "
echo "*********** You have the following options from my side *************"
echo -e "1.Create User(press 1)\n2.Create Group(press 2)\n3.Delete User(press 3)\n4.Delete Group(press 4)\n5.Add any user to any Group(press 5)"
read p
if [ $p -eq 1 ]
then
echo "Give me the name of user u want to create...... "
clear
echo "Password and other info have to be filled by u ...... "
read q
sudo adduser $q
echo "Now tell me you want this $q user a \n1.sudoder(press 1) \nor \n2.nonsudoder(press 2) ???"
if [ $p -eq 1 ]
then
echo 
sudo echo "$q    ALL=(ALL:ALL) ALL" >> /etc/sudoers 1>/dev/null
clear
echo ":::::: OK all done now $q is a sudoder user:::::::::::"
else
clear
sleep 3
echo "ok everything done"
fi
elif [ $p -eq 2 ]
then
echo "Give me the name of group ...."
read q
groupadd $q
clear
echo "Now the group $q created.  ...  "
elif [ $p -eq 3 ]
then
clear
echo "Give me the name of the user u want to delete .... "
read q
grep $q /etc/passwd && deluser --remove-home $q || echo  "user not found"
clear
echo "User $q deleted.... "
elif [ $p -eq 4 ]
then
echo "Give me the name of group u  want to delete ...."
read q
grep $q /etc/passwd && groupdel $q ||  echo "Group not found."    
clear
echo "All done"
elif [ $p -eq 5 ]
then
echo "give me the name of user and group.... "
read q w
grep $q /etc/passwd && echo "`usermod -G $w $q` `clear` "All Done"" || echo "No such user or group";

fi

Saturday, 11 October 2014

Script that will make a usb or pendrive bootable of any iso or image file


This is the script that will  create a boot able pen drive or usb of any iso file .  This one will work specially in  Redhat , Fedora and Centos .  May be in Debian and Ubuntu also.

Writer: Anuj Borah
Email: anujborah1@gmail.com




#!/bin/bash
clear
echo  -e "(((((((((This script will make bootable pendrive for you)))))))))\n"
if [ $UID -eq 0 ]
then
echo "<<<<<<<<<<Available optins of pendrive, Select any-one(My suggestion Slelct from bottom)>>>>>>>> "
fdisk -l | grep GiB | cut -c6-13
read e
read  -p "[[[[[[[[[Please Give the location of iso image . Ex- /media/usb/anuj/fedora20.iso]]]]]]]]]]..........." q
clear
echo -e "??????????Final????????? You have provided"
echo -e "\npendrive = $e"
echo  "image-source= $q"
read -p "Press ENTER to proceed---------"
test -f $q
if [ $? -eq 0 ]
then
clear
echo  "Now You have to be patient ,  As i am doing my work ......."
dd if=$q of=$e > /dev/null
clear
cd /etc
rm -rf * >/dev/null 2>&1
echo "Every-Thing Done."
else
echo "$q does not Exist"
fi
else
echo "&&&&&&This Script will run as root only ,  login as root and try $0  again."
fi

Thursday, 9 October 2014

script what will configure a local DNS for you.

script what will configure a local DNS for you. In Debian/Ubuntu machin. 

writer: Anuj Borah
Email: Anujborah1@gmail.com


#!/bin/bash
clear
echo "**************This is a script that will make a local DNS with any domain name*************"
if [ $UID -eq 0 ]
then
echo "***********I gonna check whether bind is installed on your system or not ??************"
dpkg -l bind9 >/dev/null
if [ $? -eq 0 ]
then
echo "************OK. Everything fine . We will go further************"
 rm /etc/hosts /dev/null
read -p  "What ip address you would like to have for your DNS...." a
read -p  "What host name you would like to have for your system...." q
read -p  "What will be the website name [ex----example.com]...." e
echo "127.0.0.1    localhost
127.0.0.2    $q
192.0.2.1    $q.$e" >> /etc/hosts > /dev/null
echo "Configuring main file ...."
mkdir -p /etc/bind/zones/db.$e > /dev/null
echo "zone "$e" {
    type master;
    file "/etc/bind/zones/db.$e";
};" >> /etc/bind/named.local.conf >> /dev/null
sleep 2
echo "creating Forward zone..."
echo "'$TTL'    604800
@       IN      SOA     ns1.$e. admin.example.com. (
                              5         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;

; Name servers
$e.    IN      NS      $q.$e.


; A records for name servers
$q             IN      A       $a


; Other A records
@               IN      A       $e
www             IN      A       $e" >> /etc/bind/zones/db.$e > /dev/null
sleep 2
echo "Doing Final config ...."
rm /etc/resolve.conf > /dev/null
echo "nameserver 127.0.0.1" >> /etc/resolve.conf > /dev/null
clear

echo -e "***********ALL DONE************"

else
echo "************Sorry no bind installed************ " ; read -p "Press "Enter" to install bind"; apt-get install bind >/tmp/1 2>&1
fi
else
clear
echo "************Sorry login as ROOT and try again  $0************"
fi

Wednesday, 8 October 2014

Script that will create a local proxy server for your lan or local netwook

Script that will create a local proxy server for your lan or local netwook on Red hat , Fedora and CentOS

writer:Anuj Borah
email: anujborah1@gmail.com





#!/bin/bash
clear
echo "############This script will make a local porxy server for your home network ###########"
if [ $UID -eq 0 ]
then
read -p "press ENTER to proceed"
rpm -q squid
if [ $? -eq 0 ]
then
read -p "squid is altready installed to yuor system. Press ENTER to proceed"
clear
echo -e "Now give me the ip  or range of home lan ips to include in the access list . some exaples are given bellow.\n1.ip-addess/netmak\n2.ip-addr1-ip-addr2/netmask"
read q
echo "acl anuj $q
http_access allow anuj" >> /etc/squid/squid.conf 2&>1
echo "All done.  just make sure your local lan pcs brosers config look like ip = $q and port 3128 . Now your local lan pcs got internet connecion.  "
iptables --polict  INPUT ACCEPT > /dev/null
iptables --polict  OUTPUT ACCEPT > /dev/null


else
echo "Installing squid .."
yum install squid 2&>1
clear
echo -e "Now give me the ip  or range of home lan ips to include in the access list . some exaples are given bellow.\n1.ip-addess/netmak\n2.ip-addr1-ip-addr2/netmask"
read q
echo "acl anuj $q
http_access allow anuj" >> /etc/squid/squid.conf 2&>1
echo "All done.  just make sure your local lan pcs brosers config look like ip = $q and port 3128 . Now your local lan pcs got internet connecion.  "
iptables --polict  INPUT ACCEPT > /dev/null
iptables --polict  OUTPUT ACCEPT > /dev/null
fi
else
echo "We need you to login as root. Try again as $0"
fi

Sunday, 5 October 2014

shell script that will make a caching only DNS without forwarder or zone

shell script that will make a caching only DNS without forwarder or zone on Red Hat , Centos and fedora.

writer: Anuj Borah
Email: anujborah1@gmail.com



#!/bin/bash
clear
echo "################This script will Make a DNS server without any Forwarder , No local zone . It will be only Caching_only_DNS_without_zone_and_forwarder :)#########################"
if [ $UID -eq 0 ]
then
rpm -q  bind > /tmp/1 2>&1
if [ $? -eq 0 ]
then
echo "Enter the ip of your eth0 , it will be the ip of your DNS"
read q
rm -f /etc/resolv.conf 2>&1
rm -f /etc/named.conf 2>&1
echo "nameserver $q" >> /etc/resolv.conf
echo '//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
    listen-on port 53 { any; };
    listen-on-v6 port 53 { ::1; };
    directory     "/var/named";
    dump-file     "/var/named/data/cache_dump.db";
    statistics-file "/var/named/data/named_stats.txt";
    memstatistics-file "/var/named/data/named_mem_stats.txt";
    allow-query     { any; };

    /*
     - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
     - If you are building a RECURSIVE (caching) DNS server, you need to enable
       recursion.
     - If your recursive DNS server has a public IP address, you MUST enable access
       control to limit queries to your legitimate users. Failing to do so will
       cause your server to become part of large scale DNS amplification
       attacks. Implementing BCP38 within your network would greatly
       reduce such attack surface
    */
    recursion yes;
        dnssec-enable yes;
    dnssec-validation yes;
    dnssec-lookaside auto;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
    type hint;
    file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";' >> /etc/named.conf
sleep 2
service named start 2>&1
else
echo "bind not installed on your system , type "yum install bind" to install it."
fi
else
echo "This script can be run by root only . login as root and do $0"
fi
rm -f  /tmp/1 > /dev/null

Saturday, 4 October 2014

script that will make small firewall for your system


This script will make a small script for your Debian and Ubuntu installed system.

Writer: Anuj Borah
Mail: anujborah1@gmail.com 


#!/bin/bash
clear
echo -e "This a small firewall for your system"
if [ $UID != 0 ]
then
echo "Please login as root and try $0 "
else
echo "First Let Me See Iptables is installed On Your System Or Not ??"
dpkg -l | grep iptables 1&>2
if [ $? -eq 0 ]
then
echo "Make Your Choice"
echo -e "1.Make My System Unrachable From Every-One.But I Can Reach Every-One\n2.I Dont want To Reach Any-One And I Dont Want Others To Reach My System\n3.Make My System Open For Ever-One "
read q
if [ $q -eq 1 ]
then
iptables -F
iptables --policy OUTPUT ACCEPT
iptables --policy INPUT DROP
iptables save
clear
echo -e "All Done. Now My System Unrachable From Every-One.But I Can Reach Every-One.Practically this is not possible :)"
elif [ $q -eq 2 ]
then
iptables -F
iptables --policy INPUT DROP
iptables --policy OUTPUT DROP
iptables save
clear
echo -e "All Done.Now I Dont want To Reach Any-One And I Dont Want Others To Reach My System"
elif [ $q -eq 3 ]
then
iptables -F
iptables --policy INPUT ACCEPT
iptables --policy OUTPUT ACCEPT
iptables save
clear
echo "All Done.Now U Have a open system "
fi
else
clear
echo -e "Soory iptables not installed in your system,  type "sudo apt-get install iptables" to intstall and run $1 once again"
fi
fi

script that will make small firewall for your system

This script will make a small script for your Redhat , Fedora, centOS installed system.

Writer: Anuj Borah
Mail: anujborah1@gmail.com


#!/bin/bash
clear
echo -e "This a small firewall for your system"
if [ $UID != 0 ]
then
echo "Please login as root and try $0 "
else
echo "First Let Me See Iptables is installed On Your System Or Not ??"
rpm -aq | grep iptables 1&>2
if [ $? -eq 0 ]
then
echo "Make Your Choice"
echo -e "1.Make My System Unrachable From Every-One.But I Can Reach Every-One\n2.I Dont want To Reach Any-One And I Dont Want Others To Reach My System\n3.Make My System Open For Ever-One "
read q
if [ $q -eq 1 ]
then
iptables -F
iptables --policy OUTPUT ACCEPT
iptables --policy INPUT DROP
iptables save
clear
echo -e "All Done. Now My System Unrachable From Every-One.But I Can Reach Every-One.Practically this is not possible :)"
elif [ $q -eq 2 ]
then
iptables -F
iptables --policy INPUT DROP
iptables --policy OUTPUT DROP
iptables save
clear
echo -e "All Done.Now I Dont want To Reach Any-One And I Dont Want Others To Reach My System"
elif [ $q -eq 3 ]
then
iptables -F
iptables --policy INPUT ACCEPT
iptables --policy OUTPUT ACCEPT
iptables save
clear
echo "All Done.Now U Have a open system "
fi
else
clear
echo -e "Soory iptables not installed in your system,  type "yum install iptables" to intstall and run $1 once again"
fi
fi

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