identifying what's running ( was Re: [Novalug] "10 Linux commands you've never used" article)
Beartooth
karhunhammas@Lserv.com
Fri Feb 23 14:03:28 EST 2007
On Thu, 22 Feb 2007, donjr wrote:
> On Thu, 2007-02-22 at 15:18 -0800, Beartooth wrote:
[...]
>> 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 ~]$
>
> Did you set the execute bit?
Errr... Duhh... (see below)
> Or you can run the command as:
> sh ./WhatsitDo2
That gets me only "sh: ./Whatsitdo: No such file or
directory" -- even after the chmod
[...]
>> 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.
Aha! Not being sure whether you meant "x" to mean itself
or "<whatever>", I tried it verbatim -- and sure enough, it ran.
So I guess now I just go through all of yesterday's crop,
doing chmod +x <whatever>; figure out which is which; and remove
all but the best couple. (nano -w will tell me which have the
'sort -u' in them.)
>>> 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
[...]
Looks like that's one of the ones to keep.
> 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.
I knew that part. The new and weird discovery is that the
creator of a file doesn't automatically get execute permission. I
suppose there's a reason, based on experience; but I don't
believe I've run into it before.
> 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.
Hmmm ... I got to the man page for sh (after first
hitting one for bash, which is what I run, an all I've ever run;
it seems to be the RH/FC default) -- and it's one of the most
opaque I've struck yet. Alpha-Double-Plus-Technoid-level stuff
...
But the bash page did tell me, before I got lost there,
that bash is meant to be sh-compliant, or -compatible, or
whatever the term is. I suppose that's why sh ./name_of_script
doesn't help ...
Many thanks!
--
Beartooth Neo-Redneck, Linux Evangelist
http://www.gnu.org/philosophy/no-word-attachments.html
More information about the Novalug
mailing list