LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-13-2011, 06:05 AM   #1
tony1969
LQ Newbie
 
Registered: Aug 2011
Location: newquay, cornwall
Distribution: ubuntu 10.4
Posts: 2

Rep: Reputation: Disabled
locate directory and change permissions in bash script


i am trying to write a script that does the following..

1. checks if a directory exists
2. changes permisssions of the directory

i have written a script but it returns a message to say that the specified
directory does not exist (but it does).

my question is how to i search the entire file system as directory could potenially be anywhere. would cd or su be of any use here.

advanced apologies incase this is a dumb question but it's my first
thanks tony.
 
Old 08-13-2011, 06:10 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Welcome to LQ.
Perhaps you can post the script which gives the error.

Kind regards
 
Old 08-13-2011, 07:02 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,493

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
I am with repo. Without seeing what you have done it is not possible to help further without just doing the work for you.
 
Old 08-13-2011, 07:04 AM   #4
tony1969
LQ Newbie
 
Registered: Aug 2011
Location: newquay, cornwall
Distribution: ubuntu 10.4
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile

my script is as follows...

#!/bin/bash
# author: t.holloran
# date: july 22 2011
# Purpose: locate directory and change permissions.

clear
directory_name=dname

function exall()
{
chmod 740 $dname
ls -sail | head
}
echo "Please enter a directory_name"
read dname
echo $dname " will now be revised"
zenity --question # are you sure you want to proceed NO YES

if [ -d $dname ]
then
echo "the present permissions are:"
cd $dname ; ls -sail | head
echo "requested changes have now been applied as below"

cd $dname
exall

else
echo "directory " $dname "does not exist!"
echo "please check and try again"
fi
#END
 
Old 08-13-2011, 09:30 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,493

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Ok ... let us start at the beginning:

1. Please place code in [code][/code] tags so it can be read better and formatting is kept.

2. bash is a top down language, meaning you have a line:
Code:
directory_name=dname
The issue here is dname has not been set yet so directory_name will always be blank.

3. You need to provide more information to the user. You have asked for a directory name when in fact it is relative, meaning that any directory given must be in the current directory
to be accessed. Is this what you intended?

4. The following code does not make sense to me:
Code:
cd $dname ; ls -sail | head
echo "requested changes have now been applied as below"

cd $dname
exall
a. Are we interested in the directory or its contents?
b. head will just return everything from the ls command so what is the point?
c. requested changes have now been applied as below ... what changes? nothing has been done yet. Maybe it is a grammatical error here.
d. cd into the same directory again which implies that a directory with the same name is inside the one you already went into .. is this correct? if not this line will throw an error.
e. Now you call a command which is trying to change the permissions on yet another directory or file with the same name as the original directory??? Again I am not sure this is what you want.

5. Lastly, the function does the same pointless ls / head combination.


Now I know i didn't specifically answer any questions, but if you look into the above it should help you toward an answer.

I am happy to answer any further questions if you have them based on what I have written.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the permissions the whole directory? pratikvimal Linux - Newbie 10 06-12-2009 10:13 AM
Unable to change directory on terminal using bash script gregorian Linux - Newbie 11 02-05-2007 03:17 AM
How do I change directory permissions ? cwolf78 Linux - Software 3 05-05-2005 12:15 PM
can't change directory permissions walterbyrd Debian 7 07-24-2004 01:20 PM
How do I Change directory permissions? Stevetgn Linux - Newbie 8 06-09-2004 12:09 AM


All times are GMT -5. The time now is 12:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration