Re: possible shell script solution
From: Christo (chris_at_juststuffd.co.uk)
Date: 12/03/04
- Next message: Bridge: "Java WebServer Virtue host"
- Previous message: ohaya: "Re: Installed NIS+ master root server - keylogins fail"
- In reply to: Christo: "possible shell script solution"
- Next in thread: Michael Tosch: "Re: possible shell script solution"
- Reply: Michael Tosch: "Re: possible shell script solution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 3 Dec 2004 01:52:44 -0000
"Christo" <chris@juststuffd.co.uk> wrote in message
news:315s7mF37shksU1@individual.net...
> ok i posted earlier and thank you for all your replies, i have looked at
> your methods and tried to digest them and even tested a few, but none
> worked to my advantage unfortunately.
>
> i have posted a new thread because the other one was massive and strayed
> OT so here we go....
>
> I am a total novice and have no prior experience to shell scripting so
> please bare with me
>
> I have come up with this however there are several parts of it which i am
> not too sure about and wanted to check with you people here
>
> the purpose of the script (for people not familiar with the previous pst)
> is to list directories and files by simply listing their name, but only to
> list directories and files that are writeable by group and other it doesnt
> matter if they are writeable by owner or are readable etc as long they
> have a w in c6 and c9 so i have came up with this, it also must count the
> files and display the figures at the bottom of the script.
>
>
> #!/bin/sh
>
> dcount=0
> fcount=0
>
> for fn in *
> do
>
> dir=`ls -ld $fn | cut -c1`
> name=`ls -ld $fn | cut -c55-75`
> gwrite=`ls -ld $fn | cut -c6`
> owrite=`ls-ld $fn | cut -c9`
>
> if [ $gwrite = 'w' -a $owrite = 'w' ]
> then
>
> #havent been taught boolean in shell scripting at uni yet
> #but do i set the value with `` quotes or with '' quotes?
> #i simply want the write variable to hold the value w
> write=`w`
>
> if [ $dir = 'd' -a $write = 'w']
> then
>
> #below i am not sure if this will work? adding to the
> #dcount and adding to the fcount like this and also
> #outputting the names, seen as how both file names and
> #directory names share the same variable?
> #can anyone post a solution to this?
>
> dcount=`expr $dcount + 1
> echo "$name (DIR)"
> fcount=`expr $fcount +1
> echo "$name"
> else
> echo "0 files/dirs writeable by group and other"
> fi
> fi
> done
>
> echo "\n"
> echo "Counted $fcount Files"
> echo "Counted $dcount directories"
>
> any help here would be much appreciated, I am getting there eventually on
> my limited knowledge, i havent been taught any shell scripting this
> assignment is entirely based on me researching from the start, we have of
> course been told very basic stuff like the structure of the language and
> numerous commands and stuff, but nothing solid that can be put to good
> practice in creating a script such as this.
>
> thanks for your time
>
> Chris
>
this is proving quite difficult for me i have tried peoples suggested
scripts and they are failing for reasons i dont know.
i have managed to be able to get a list from one of the following methods
ls -l | cut -c55-75
this will list everything including directories
i have also managed
if [ -f $fname ]
then
echo "$fname (File)"
else
echo "$fname (DIR)"
fi
i am not sure how ths works, what exactly does -f do? and will -d do the
same except replace where the file is echoed the directory will be echoed?
i have tried this which is totally off
dir=`ls -ld $fn | cut -c1`
if [ $dir = 'd' ]
then
echo "Writeable directories"
ls -l | cut -c55-75
else
echo "no writeable directories"
fi
the test will figure if the file is a sirectory, but the command ls -l |
cut -c55-75 will display all available contents of directory
can anyone tell me how to change the command
ls -l | cut -c55-75
so it will list only directories and not files too
if i can get that sorted i will b somewhat where i want to be,
able to list directories only
i could then try
owrite=`ls-ld $fn | cut -c9`
gwrite=`ls -ld $fn | cut -c6`
if [ owrite = 'w' && gwrite = 'w']
then
write="w"
if [ $dir = 'd' && $write = 'w']
then
ls -l | cut -c55-75
#the above ls command doesnt work the way i want
#but a command that will list only directories?
is this right?
or is it -a for and and -o for OR?
i have been getting errors in my scripts with missing [] characters?
i am a total novice, this is a hard script for me to write, however what i
have learnt is that people who work in unix daily... are really cool people,
it must take so much time to get scripts and commands and stuff setup and
personalized.
anyhow any help would be much appreciated
can anyone point me to a good online tutorial on shell scripting?
the stuff we have from lectures is pretty crappy only scratches the
surface.... any reference material other than the long and horribley
designed man pages would be great
i have tried man test and i think i found test operators are -a and -o for
and and or?
i have been using || and &&
and is it
if [bah] && [bah]
or
if [ bah && bah ]
- Next message: Bridge: "Java WebServer Virtue host"
- Previous message: ohaya: "Re: Installed NIS+ master root server - keylogins fail"
- In reply to: Christo: "possible shell script solution"
- Next in thread: Michael Tosch: "Re: possible shell script solution"
- Reply: Michael Tosch: "Re: possible shell script solution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|