identifying what's running ( was Re: [Novalug] "10 Linux commands you've never used" article)
Beartooth
karhunhammas@Lserv.com
Thu Feb 22 18:18:39 EST 2007
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@localhost ~]$ ./WhatsitDo2
bash: ./WhatsitDo2: Permission denied
[btth@localhost ~]$
This despite the fact that I *created* the confounded
file as btth. So I tried it as root :
[root@localhost ~]# ./WhatsitDo2
-bash: ./WhatsitDo2: No such file or directory
[root@localhost ~]#
Hmmm -- well, obviously (I think), try :
[root@localhost btth]# cp WhatsitDo2 /root
[root@localhost btth]#
and try it again. Oddzooks! Ye gods & little fishes!
[root@localhost ~]# ./WhatsitDo2
-bash: ./WhatsitDo2: Permission denied
[root@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??
> 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@localhost ~]$ nano -w WhatsitDo3
[btth@localhost ~]$ ./WhatsitDo3
bash: ./WhatsitDo3: Permission denied
[btth@localhost ~]$
> 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?
--
Beartooth Neo-Redneck, Linux Evangelist
http://www.gnu.org/philosophy/no-word-attachments.html
More information about the Novalug
mailing list