LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (http://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   question regarding bash script variable (http://www.linuxquestions.org/questions/linux-desktop-74/question-regarding-bash-script-variable-796967/)

mrmnemo 03-21-2010 11:32 PM

question regarding bash script variable
 
hi,

i was wonder how i would make a script to run a search for a list of bin files and write to an array or assign each each given bin to a a script defined command. like ls /sbin | grep iptables > myarray?
the thing is: i need to search for more than one bin file so the script will know where to locate the commands so that its more portable. so if i could run the above command combination against a list of bins to locate? i am aware that stdout to array is done in a diff way than i post above.

thanks in advance.

catkin 03-21-2010 11:54 PM

What do you mean by "bin" files? Files in "bin" directories or binary files? If the latter, have you explored the file command? Getting the names of the files into any array is easy; finding the files is harder
Code:

i=0
while read
do
    array[$i]="$REPLY"
    let i++
done < <$( <code to find files> )

:

mrmnemo 03-22-2010 12:09 AM

Quote:

Originally Posted by catkin (Post 3907144)
finding the files is harder
Code:

i=0
while read
do
    array[$i]="$REPLY"
    let i++
done < <$( <code to find files> )

:

ahh i forgot inverse stdout. bianary files like iptables / modprobe / ect.
as to code to find files: so would i have ls read from a list tehn piped to grep then to array?
ls /sbin | grep << cmd.conf
? would that repeat the search until all bianary files are found?
o yeah....thanks again for the help

catkin 03-22-2010 12:46 AM

Quote:

Originally Posted by mrmnemo (Post 3907161)
bianary files like iptables / modprobe / ect.

That does not answer the question. The examples you give are both binary files and in bin (actually sbin) directories.

Quote:

Originally Posted by mrmnemo (Post 3907161)
as to code to find files: so would i have ls read from a list tehn piped to grep then to array?
ls /sbin | grep << cmd.conf
? would that repeat the search until all bianary files are found?

If you have a list of binary (executable?) files then what value is grep adding?

"Binary" is sometimes used to mean non-text files. Are you interested in only binary executables?

Binary files may be in any directory; to find them all you will have to search the entire file system hierarchy. Are you interested in all such files or only such files as a non-root user can use? The find command is a good tool for looking for files. Using options -type f and -executable will restrict the number of hits and may be "good enough" for what you are trying to do?

What are you trying to do, by the way? There may be a better way than loading a bash array with the names of all the "bin" files on your system.

mrmnemo 03-22-2010 12:55 PM

well what i am trying to do is something that is already been done( at least i think it has) but its just spread across a few diff scripts. All i want to do is a basic post install script which will address: non-free sources ( codec for multimedia, etc), 3rd party repo set up and config them to take backseat to distro specific update repo, iptables configuration, denyhosts install and config, ssh daemon config, some basic browser plugin stuff ( flash _i686 / x64 ). I have noticed that lots of people migrating to linux seem to have issues in this area. while i realize that some distros focus on this thing or the other....some of the basic stuff is always left undone. I am by NO means a guru. however, after so many hosed installs ( due to user error ) i have noticed myself performing certain actions over and over.
I have been doing some limited scripting.
I have figured out alot of the commands taht i would enter at the prompt to attain my goals.
I have gotten tired of doing it by hand all the time.
Why not just make a script that you can run once that will install everything you'll need to cover a non production enviroment ( i.e. home desktop) with multimedia support(play-edit-burn), some of the basic security stuff ( denyhosts, host files, iptables, ssh, log monitor, portsentry or somthing like that), web browser plugins ( privoxy/tor,flash, ect..) while it may seem trivial...i think alot of folks would appreciate it.

Also, i realize that some scripts already exist ( easy life and the like ). However, the y seem to be distro specific. so i was thinking that a script which could id the distro ( via uname or user input ) and search for the need binary files to run a set of commands ( as stated above ) would be neato. The funny thing is...alot of it I will be able to cut and past from scripts already floating around. Just maybe need to have the script use variables for each distro. yum vs apt would require a lil bit more work but svn ( xbmc install ) and denyhosts, iptables all have commands that stay kinda portable..I thikn.

By the way, thanks for taking the time and showing support for this. 8))


All times are GMT -5. The time now is 01:21 PM.