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










2 comments:

  1. Drawback of the script
    1) It does not take backup of hidden directories and hidden files.
    2) It copies on first level only. It should not take back up of directories instead it should go inside the directories and subdirectories and take back up of files so every backup file will be placed beside itself.
    3)And if you are just copy files and directories beside it, why these lots of ifs and elses, rsync can easily do this.
    You can see my blog, how eaily and efficiently it can be done.
    http://amitmund.blogspot.in/2013/10/rsync-and-rdiff-backup.html

    ReplyDelete
  2. Thanks dude , i will publish another one .

    ReplyDelete

Popular Posts