Click to See Complete Forum and Search --> : Need affirmation
Bill Case
03-01-2004, 11:38 PM
I am working at home alone so I can't ask the guy in the next office for a quick affirmation to the following four bash script questions.
1) If shell doesn't tell me that I have a permission problem, can I be certain that I, in fact, don't have a permission problem ? Or, do I have to checkout my permissions anyways when I am returned an error?
2) If I run rpm -qa can I be certain that I have all my installed rpm's no matter where I origanally got them ?
3) How can I use 'ls -xxx' to get just a recursive list of directories and sub-directories but without files? Or, maybe I can't be done? I am trying to avoid using 'tree'.
4) Is there any way that I can write a seperate script for 'find' that 'find', will call?
I am thinking of the '-f' [scriptname] in 'awk' and 'sed' where I can build a complex search path, and/or options, tests, and actions seperately then use it with the '-f' option. '-exec' doesn't seem to let me built complex searches with '-prune' etc. Maybe I am not using it correctly. If I should be able to build such a script please tell me so. Just knowing I can, I should be able to figure out how.
I have read, re-read, printed and googled, so a quick short affirmation or denial would be all I need.
Thanks
Bill
JThundley
03-02-2004, 12:15 AM
Wow that was confusing to read.. I still don't really get what you need help with except for the recursive listing...
To do that: find . -type d -print
find files in the current directory of type directory and print them.
Hope this helps..
Bill Case
03-02-2004, 01:09 AM
As soon as I read your "find . -type d -print" - I said of course.
Thank you.
I will try to be less confusing on the other questions.
1) I am pretty sure that unless shell says something like "you do not have permission to run that file" or "Can not read file xxx" at the command line then I do not have to waste time looking for a permission problem when I try to fix a scrpting error.
I just wanted someone with more experience to confirm that was true or to tell me "No sometimes bash commands/programs don't flag a permission problem."
2) I have run rpm -qa > rpmnamefile and from my memory It seems that some of the rpm's I have downloaded are not included. So I was asking someone with more experience than I have "Is it possible to run 'rpm -qa' and miss some rpms?"
4) I don't know how to be more explicit but I'll try. I want to write a file/script that contains a search path like {eg. search directory A and all its subdirectories; then search directory B but skip (-prune) this subdirectory; then search directory C at the first level only ... etc.} Don't worry, I can write the appropriate search path.
What I haven't been able to do is to make 'find' call the script/file and use my scripted search path. What I wanted to hear from someone more experienced than me was that using -exc or some other 'find' option, I should be able to use a scripted search path.
I don't need to know how to write my scripted search path particularly, at this point I would be happy knowing whether it is even possible to make 'find' call/use a scripted search path.
JThundley
03-02-2004, 03:59 AM
hmmmm... It's kinda hard to say without having the script in front of me... say, can I get the script in front of me? Post it or email it or PM it to me and I'll help all I can, I am pretty good at shell scripting for an 18 year old.:eek:
Bill Case
03-02-2004, 05:15 PM
Jthundley - once again thnaks.
I am appreciative of all the help I can get. I will post what I have done, what has worked, and what I am trying to do, tomorrow evening.
I still would like a yes/no to the other two questions -- anyone please.
For now I have to work on a project that pays money!
Thanks
From Bill -- someone who hasn't seen 18 years of age for a long, long time.
bwkaz
03-02-2004, 08:50 PM
Originally posted by Bill Case
1) I am pretty sure that unless shell says something like "you do not have permission to run that file" or "Can not read file xxx" at the command line then I do not have to waste time looking for a permission problem when I try to fix a scrpting error.
I just wanted someone with more experience to confirm that was true or to tell me "No sometimes bash commands/programs don't flag a permission problem." The only way that I know of that that would happen is if your script is redirecting the standard error stream of the program that you're running somewhere else (you're not doing 2>/dev/null, are you?).
2) I have run rpm -qa > rpmnamefile and from my memory It seems that some of the rpm's I have downloaded are not included. So I was asking someone with more experience than I have "Is it possible to run 'rpm -qa' and miss some rpms?" I doubt it... unless you haven't installed them yet. rpm -qa lists everything that's listed in your RPM database. To be absolutely sure it's correct, you can rpm --rebuilddb to rebuild the RPM database. But that shouldn't be necessary, most of the time.
Bill Case
03-05-2004, 07:08 PM
No, I am not piping anything off to 2>dev/null.
I asked about permissions because being relatively new to scripting, as an act of desperation and fustration, I found myself playing around with my permissions when I had an error I couldn't seem to solve. Logically this was stupid; but when you can't think of anything else to check ....
I just needed a kind of 'school marm' to slap my knucles and say stop it -- find the real problem. In an office setting you can casually double check with the resident expert and that would be enough.
By the way, the errors were always typos or gross stupidities.
If you think I've wasted your time, all that I can say is that a Doctor once told me "Its as important to know your not sick as it is to know the name of the disease."
Thanks again for both answers.
Bill
Bill Case
03-05-2004, 07:36 PM
I appreciate your prior offer to help with my 'find' script.
Below is a test script that I have that works
# ./Billfind.sh Billfindtest.txt
#####
#! /bin/bash
#
# A test utility to find files on a limited search path.
#
# Billfind.sh
# # # # # # # # # # # # # # # # # # # # # # # # # #
clear; echo
find / \
-path /root/.Trash -prune -or \
-path /usr/etc -prune -or \
-path /usr/man -prune -or \
-path /usr/share/doc -prune -or \
-path /usr/share/man -prune -or \
-path /usr/shre/info -prune -or \
-path /usr/src -prune -or \
-path /dev -prune -or \
-name $1
#END#
This has a fairly lengthy search path. I would like to bundle just the search path in a file or script or something; name it something short and sweet eg. 'mlike' for 'most likely find'
another search path 'like' for 'likely find' and 'ulike' for 'unlikely to find'.
Then, when I am looking for a file I can look in 'mlike', 'like' and, 'ulike' in turn. 'mlike', for example would
be
" -path /root/.Trash -prune -or \
-path /usr/etc -prune -or \
-path /usr/man -prune -or \
-path /usr/share/doc -prune -or \
-path /usr/share/man -prune -or \
-path /usr/shre/info -prune -or \
-path /usr/src -prune -or \
-path /dev -prune -or \
The actual 'find' command used at the command-line would be simple and look like:
# find / 'mlike' myfile.txt, or
# find / -exec mlike -name myfile.txt
bwkaz
03-05-2004, 08:07 PM
find / $(cat /path/to/mlike) myfile.txt
Or, to save a process:
find / $(</path/to/mlike) myfile.txt
Bash will execute the "cat" and subsitute its output in for the $(...) stuff. In the second example, bash will read the mlike file and subsitute its contents (which accomplishes the same thing as the cat version, it just saves you from starting up the extra process).
Bill Case
03-05-2004, 10:20 PM
Exactly; Thanks