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





   

No comments:

Post a Comment

Popular Posts