identifying what's running ( was Re: [Novalug] "10 Linux commands you've never used" article)
donjr
djr1952 at hotpop.com
Thu Feb 22 18:45:11 EST 2007
On Thu, 2007-02-22 at 15:18 -0800, Beartooth wrote:
> On Thu, 22 Feb 2007, donjr wrote:
>
>
> > Like all shell scripts the first #! must be the first two(2) characters
> > of the file.
>
> Well, I had a blank line at the top. Got rid of it -- and
> now the complaints are about line 9 ...
>
> >> Now running it gives me a bunch of :
> >>
> >> ../WhatsitDo: line 10: [: missing `]'
> >> ../WhatsitDo: line 10: [: missing `]'
> >> ../WhatsitDo: line 10: [: missing `]'
> >> ../WhatsitDo: line 10: [: missing `]'
> >>
> >> Trouble is, I'm unclear whether "line 10" counts the
> >> commented out lines, or the blank line, or both, or neither. And
> >> I don't see a "[" to mate another "]" to.
> >>
> >> Here's what I have, if email formatting doesn't mess it
> >> up :
> >>
> >> GNU nano 1.3.12 File: WhatsitDo
> >>
> >>
> >> #!/bin/sh
> >> #
> >>
> >> LAST=none
> >> for PREPROCESS in $(ps -e | awk '{print $4}') ; do
> >> PROCESS=${PREPROCESS//\/0}
> >> MAN=$(man -f ${PROCESS})
> >> TEST_MAN=${MAN//nothing appropriate}
> >> if [ "${#MAN}" = "${#TEST_MAN}" -a "${PROCESS}" != "${LAST}"]
> >> ; then
> >> LAST=${PROCESS}
> >> echo ${MAN}
> >> echo
> >> fi
> >> done | less
> >>
> >> (In my actual file, the long line has ], then
> >> space-semicolon-space, then the word 'then' with a space after
> >> it -- which is not how it looks above on this end.) Can any of
> >> you tell what I've still got wrong??
> >
> > Then try the following versions (I also made sure that all lines are
> > less then 75 characters, so line wrap shouldn't be a problem either):
> >
> > #!/bin/sh
> > #
> > for PREPROCESS in $(ps -e|awk '{print $4}'|sort -u)
> > do
> > PROCESS=${PREPROCESS//\/0}
> > MAN=$(man -f ${PROCESS})
> > TEST_MAN=${MAN//nothing appropriate}
> > if [ "${#MAN}" = "${#TEST_MAN}" ]; then
> > echo ${MAN}
> > echo
> > fi
> > done | less
>
> Ver-r-rry innter-r-rressttingg. I c&p'd that into
> WatsitDo2, then deleted the "> " from the start of each line,
> saved it, and ran the new version :
>
> [btth at localhost ~]$ ./WhatsitDo2
> bash: ./WhatsitDo2: Permission denied
> [btth at localhost ~]$
Did you set the execute bit?
Or you can run the command as:
sh ./WhatsitDo2
> This despite the fact that I *created* the confounded
> file as btth. So I tried it as root :
>
> [root at localhost ~]# ./WhatsitDo2
> -bash: ./WhatsitDo2: No such file or directory
> [root at localhost ~]#
>
> Hmmm -- well, obviously (I think), try :
>
> [root at localhost btth]# cp WhatsitDo2 /root
> [root at localhost btth]#
>
> and try it again. Oddzooks! Ye gods & little fishes!
>
> [root at localhost ~]# ./WhatsitDo2
> -bash: ./WhatsitDo2: Permission denied
> [root at localhost ~]#
>
> Here I get nervous. I did "chown -R btth:btth /home/btth"
> on a whole wad of files I had scp'd from another machine
> recently. So I *think* I do "chown root:root /root" now -- izzat
> it??
The command you are looking for is 'chmod' as in:
chmod +x WhatsitDo2
and then it will execute as a command.
> > I used 'sort -u' (or sort --unique) to replace the "${PROCESS}"
> > != "${LAST}" related parts of the script.
> >
> > Or an even simpler version that doesn't filter out the entries
> > that man doesn't find anything appropriate for:
> >
> > #!/bin/sh
> > #
> > for PREPROCESS in $(ps -e|awk '{print $4}'|sort -u)
> > do
> > PROCESS=${PREPROCESS//\/0}
> > MAN=$(man -f ${PROCESS})
> > echo ${MAN}
> > echo
> > done
>
> [btth at localhost ~]$ nano -w WhatsitDo3
> [btth at localhost ~]$ ./WhatsitDo3
> bash: ./WhatsitDo3: Permission denied
> [btth at localhost ~]$
Try:
sh ./WhatsitDo3
> > In fact I feel that it is those entries that don't have any
> > sort of man entry that you should be most interested in finding
> > out where they came from.
>
> Yes. So do I copy and chown this one (whatever way
> works), too?
You use 'chmod' to change the file access permissions. It is the file
access permissions that control if a file is executable or not and a few
other features.
'chown' is for changing who owns of a file.
Or if you just want to execute a temporary script while testing and what
not it's far easier to just do:
sh ./name_of_script
Which is what really happens behind the screens when you execute a
command at the prompt.
--
--
Don E. Groves, Jr.
$ /usr/games/fortune :
You will be reincarnated as a toad; and you will be much happier.
More information about the Novalug
mailing list