Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > Bash shell scripting doubts

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 04-26-2007   #1 (permalink)
Just Joined!
 
Join Date: Apr 2007
Posts: 5
Unhappy Bash shell scripting doubts

i have just started out scripting and have some doubts ,

1) How do i print the file access permission(FAP) for all the type of users ??

2) how to search for files with same name in current directory ?

3) how do i validate a blank user input ? like if user doesnt enter any values and presses Enter, what condition do i put in an If construct ?

4) how to check what files were created today ? ls shows only the last modification date.

thnx for reading the post.
livingsword is offline  


Reply With Quote
Old 04-27-2007   #2 (permalink)
Linux Enthusiast
 
Franklin52's Avatar
 
Join Date: Aug 2006
Posts: 598
It's against the rules to post homework here.
Google on "howto bash scripting"

Regards
Franklin52 is offline   Reply With Quote
Old 04-27-2007   #3 (permalink)
Just Joined!
 
Join Date: Apr 2007
Posts: 5
Quote:
Originally Posted by Franklin52 View Post
It's against the rules to post homework here.
Google on "howto bash scripting"

Regards
this isnt a homework question. i found some good tutorials but i prefer practical advice on these questions.
livingsword is offline   Reply With Quote
Old 04-27-2007   #4 (permalink)
Linux Enthusiast
 
Franklin52's Avatar
 
Join Date: Aug 2006
Posts: 598
Ok, what have you tried so far?
And what goes wrong?

Regards
Franklin52 is offline   Reply With Quote
Old 04-28-2007   #5 (permalink)
Just Joined!
 
Join Date: Apr 2007
Posts: 5
Quote:
Originally Posted by Franklin52 View Post
Ok, what have you tried so far?
And what goes wrong?

Regards
well, by some research and trial n error i have solved most of the doubts to an extent ,

1)for the FAP problem , i did this,

Code:
echo -n "Enter Filename : " ; read fname ;

# check if file exists
if [ -e $fname ]
then
	 
#display fap for owner 

	echo "Owner"

	ls -l $fname|awk  '{print $1 }' |tee temp | cut -c2-4

#display fap for group users
	
	echo "Group"

	cat temp | cut -c5-7

#display fap for other users

	echo "Other"
	
	cat temp | cut -c8-10
else
	echo "FIle does not exist"
fi
the output is :

Code:
Owner 
rwx
Group
r-x
Others
r--
Now, this is an acceptable output , but i want to print the words "Read" "Write" "Execute" instead of 'rwx'. If it were only for the owner , i could use the test command and -r, -w, -x options but that doesnt work for Group and Other users, how do i do that ?
livingsword is offline   Reply With Quote
Old 04-28-2007   #6 (permalink)
Linux Enthusiast
 
Franklin52's Avatar
 
Join Date: Aug 2006
Posts: 598
An example:

Code:
#!/bin/sh

Permission()
{

for((i=0; i<3; i++))
  do
  case ${perm:i:1} in
    "r")
      printf "Read\t"
      ;;
    "w")
      printf "Write\t"
      ;;
    "x")
      printf "Execute\t"
      ;;
    esac
  done

  echo

}

echo -n "Enter Filename : " ; read fname

if [ ! -e $fname ] ; then
  echo File $fname does not exist
  exit 1
fi

fileperm=`ls -l $fname`

# I don't use a loop here to show the use of substrings
# The function Permission is called 3 times

echo Owner
perm=${fileperm:1:3}
Permission

echo Group
perm=${fileperm:4:3}
Permission

echo Others
perm=${fileperm:7:3}
Permission

exit 0
I've use a function to print out the permissions.
It's not an easy example for a beginner but spend some time to find out how it works, go here for some tutorials:

http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://tldp.org/LDP/abs/html

Regards
Franklin52 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 02:21 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2