Saturday, May 9, 2009

shell script for linux

History of all great works in to witness that no great work was ever done without either active or passive support of a person ‘surrounding and one’s close quarters . thus is it not hard to conclude how active assistance from senior could positively impact the execution of a project .I am highly thankful to our learned faculty Ms.Harleen mam for his active guidence throughout the completion of project .
Last but not least , I would also want to extend my appreciation to those who could not be mentioned here but have well played their role to inspire me behind the certain.

---Shubham Verma



Create a shell script called prog1 that will accept the input and check if the input is a directory file and is readible, writable .If so then all ordinary files under that directory should be listed out one by one.For each ordinary file that is writable the user should be asked if the file is to be deleted or not .If ‘yes’ file should be deleted else next file is checked .At the end the script should display the following message …
. . . Ordinary file deleted from the directory.
. . . Ordinary files remain in the directory.









Shorter the program greater will be its brilliancy . . .
Same is in my case Scripting is done with very simple and basic commands of Linux programming and that too not having very critical logic 
Scripting is done giving below 


vi prog1.sh
echo “Enter the Input”
read fd
if [(-d $fd)&(-r $fd)&(-w $fd)]
then
echo “ls fd”
echo “Enter the file name which is to be selected”
let i=1-100
read fn
if [-w $fn]
then
echo “Press enter to delete this file”
mkdir b
cd b
cp $b $fn
cd
rm -i $fn
else
mkdir c
cd c
cp $c $fn
cd
fi
let i=i+1
fi
echo “ls b”
echo “These many files are deleted from the directory”
echo “ls c”
echo “These many remains in the directory”

















I. Opening the vi editor.
II. Inputting the File
III. Checking the file is a directory , readible ,writable or not.
IV. If is true , then listing all files in the directory.
V. Asking the user which file is to be selected
VI. After that , taking the loop from 1 to 100 and inputting the selected file ‘fn’ ,checking whether ‘fn’ has writable permission or not.
VII. If yes, then displaying ,”Press Enter to delete this file”.
VIII. In that condition only , creating & changing the directory into ‘b’ and copying the file ‘fn’ into the directory ‘b’. And then removing the file ‘fn’.
IX. But if the condition is being false then copying the ‘fn’ into the another directory ‘c’.
X. And at the last , listing all the deleted files and remaing files from the directory ‘b’ and ‘c’.
“directory ‘b’ stores the the deleted file from the main the directory where as ‘c’ directory stores all the remaing files from the main directory.





-d checks if the file is directory or not. . .
-r checks if the file is readible or not. . .
-w checks if the file is writable or not. . .
echo It is just use to display the context to the console . . .
read It is used for initialsing and inputting the variables . . .
if[ ] It is just used for cheking out the cndition given in the program . . .
let ____ It is just to neglect the ‘$’ sign in the calculation . . .
mkdir It is just create a new directory . . .
cd It is just used to change the present working directory . . .
rm -i It is just remove the file by confirming it first . . .
cp It is just use to copy a file . . .
ls - It is just use to list the all the files in that directory . . .
-d File exist and it is adirectory . . .
-w File exist and it have readible permission to it . . .
-r File exist and it have writable permission to it . . .

fd It is the inputted directory name . . .
fn It is the file name to which user has selected from the directory fd . . .
b It is the directory to which all deleted files are stored . . .
c It is the directory to which remaining files are stored . . .
n It contains total no of files in the directory fd . . .
i It is the counter variable for the for loop from 1 to n . . .





















History of all great works in to witness that no great work was ever done without either active or passive support of a person ‘surrounding and one’s close quarters . thus is it not hard to conclude how active assistance from senior could positively impact the execution of a project .I am highly thankful to our learned faculty Ms.Harleen mam for his active guidence throughout the completion of project .
Last but not least , I would also want to extend my appreciation to those who could not be mentioned here but have well played their role to inspire me behind the certain.

---Shubham Verma



Create a shell script called prog1 that will accept the input and check if the input is a directory file and is readible, writable .If so then all ordinary files under that directory should be listed out one by one.For each ordinary file that is writable the user should be asked if the file is to be deleted or not .If ‘yes’ file should be deleted else next file is checked .At the end the script should display the following message …
. . . Ordinary file deleted from the directory.
. . . Ordinary files remain in the directory.









Shorter the program greater will be its brilliancy . . .
Same is in my case Scripting is done with very simple and basic commands of Linux programming and that too not having very critical logic 
Scripting is done giving below 


vi prog1.sh
echo “Enter the Input”
read fd
if [(-d $fd)&(-r $fd)&(-w $fd)]
then
echo “ls fd”
echo “Enter the file name which is to be selected”
let i=1-100
read fn
if [-w $fn]
then
echo “Press enter to delete this file”
mkdir b
cd b
cp $b $fn
cd
rm -i $fn
else
mkdir c
cd c
cp $c $fn
cd
fi
let i=i+1
fi
echo “ls b”
echo “These many files are deleted from the directory”
echo “ls c”
echo “These many remains in the directory”

















I. Opening the vi editor.
II. Inputting the File
III. Checking the file is a directory , readible ,writable or not.
IV. If is true , then listing all files in the directory.
V. Asking the user which file is to be selected
VI. After that , taking the loop from 1 to 100 and inputting the selected file ‘fn’ ,checking whether ‘fn’ has writable permission or not.
VII. If yes, then displaying ,”Press Enter to delete this file”.
VIII. In that condition only , creating & changing the directory into ‘b’ and copying the file ‘fn’ into the directory ‘b’. And then removing the file ‘fn’.
IX. But if the condition is being false then copying the ‘fn’ into the another directory ‘c’.
X. And at the last , listing all the deleted files and remaing files from the directory ‘b’ and ‘c’.
“directory ‘b’ stores the the deleted file from the main the directory where as ‘c’ directory stores all the remaing files from the main directory.





-d checks if the file is directory or not. . .
-r checks if the file is readible or not. . .
-w checks if the file is writable or not. . .
echo It is just use to display the context to the console . . .
read It is used for initialsing and inputting the variables . . .
if[ ] It is just used for cheking out the cndition given in the program . . .
let ____ It is just to neglect the ‘$’ sign in the calculation . . .
mkdir It is just create a new directory . . .
cd It is just used to change the present working directory . . .
rm -i It is just remove the file by confirming it first . . .
cp It is just use to copy a file . . .
ls - It is just use to list the all the files in that directory . . .
-d File exist and it is adirectory . . .
-w File exist and it have readible permission to it . . .
-r File exist and it have writable permission to it . . .

fd It is the inputted directory name . . .
fn It is the file name to which user has selected from the directory fd . . .
b It is the directory to which all deleted files are stored . . .
c It is the directory to which remaining files are stored . . .
n It contains total no of files in the directory fd . . .
i It is the counter variable for the for loop from 1 to n . . .

No comments:

Post a Comment