LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 03-21-2010, 11:32 PM   #1
mrmnemo
Member
 
Registered: Aug 2009
Distribution: linux
Posts: 527

Rep: Reputation: 51
Talking 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.
 
Old 03-21-2010, 11:54 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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> )
:
 
Old 03-22-2010, 12:09 AM   #3
mrmnemo
Member
 
Registered: Aug 2009
Distribution: linux
Posts: 527

Original Poster
Rep: Reputation: 51
Talking

Quote:
Originally Posted by catkin View Post
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
 
Old 03-22-2010, 12:46 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by mrmnemo View Post
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 View Post
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.
 
Old 03-22-2010, 12:55 PM   #5
mrmnemo
Member
 
Registered: Aug 2009
Distribution: linux
Posts: 527

Original Poster
Rep: Reputation: 51
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))
 
  


Reply

Tags
bash scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
bash script: use the directory of the script file as variable? phling Linux - Newbie 12 01-16-2010 07:16 PM
Simple variable bash script help/question lilrazzzzz Programming 4 04-29-2009 05:50 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 03:08 AM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM


All times are GMT -5. The time now is 10:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration