LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-24-2012, 03:57 AM   #1
crabchucker
LQ Newbie
 
Registered: Jan 2012
Location: New Zealand
Distribution: Arch linux, Debian
Posts: 3

Rep: Reputation: Disabled
Question Adding to DAEMONS/MODULES arrays from bash script


I have started playing around with Linux recently (mostly Arch atm) and i am trying to create a Bash script to install the main packages i will be using and to create a user, and i want to be able to add items to the modules and daemons arrays in rc.conf as in changing:

Code:
MODULES=()
to
Code:
MODULES=(vboxguest vboxsf vboxvideo)
and
Code:
DAEMONS=(hwclock syslog-ng network netfs crond)
to
Code:
DAEMONS=(hwclock syslog-ng network netfs crond sshd vbox-service dbus rpcbind)
What would be the easiest way to do this without destroying my rc.conf file(s)

Also how would i uncomment the Australia mirrors in /etc/pacman.d/mirrorlist from the script aswell

Last edited by crabchucker; 01-24-2012 at 03:30 PM. Reason: Forgot to write last piece
 
Old 01-24-2012, 04:15 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
sed with the -i option
 
1 members found this post helpful.
Old 01-24-2012, 05:41 AM   #3
crabchucker
LQ Newbie
 
Registered: Jan 2012
Location: New Zealand
Distribution: Arch linux, Debian
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for the sed command, i done a bit of searching and came across this website www.brunolinux.com/02-The_Terminal/Find_and Replace_with_Sed.html and also http://www.grymoire.com/Unix/Sed.html#uh-2 which helped me understand how to use it and it seems to be working
Code:
sed -i 's/#Server = ftp:\/\/mirror.aarnet.edu.au\/pub\/archlinux\/$repo\/os\/$arch/Server = ftp:\/\/mirror.aarnet.edu.au\/pub\/archlinux\/$repo\/os\/$arch/g' /etc/pacman.d/mirrorlist
plus about 5 more + the modules and daemons arrays, so thanks for the help ^_^
I had to place the backslashes in the url's so it registered the forward slashes in the code instead of other options

Last edited by crabchucker; 01-24-2012 at 03:28 PM. Reason: adding code tags
 
Old 01-24-2012, 09:09 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.


Perhaps a better way may be to do something like this. Modify the lines in the above script to:

Code:
MODULES=( $(</path/to/modulefile ) )
DAEMONS=( hwclock syslog-ng network netfs crond $(</path/to/daemonfile) )"
I'm assuming that this is a bash or ksh script here, as I know of no other shells that use that syntax.

Create those files and put the entries you want inside them, whitespace-delimited. The script should then import them into the arrays. Any other script you write then also only has to append values to those files to make them available.

BTW, have you checked to see whether the script doesn't already support something similar?

Edit: BTW2, your sed command can be made more readable:

Code:
sed -i 's|#Server = ftp://mirror.aarnet.edu.au/pub/archlinux/$repo/os/$arch|Server = ftp://mirror.aarnet.edu.au/pub/archlinux/$repo/os/$arch|g' /etc/pacman.d/mirrorlist
sed can use any ascii character except newline and null as a substitution delimiter, not just "/".

I'm assuming that the $variables in the urls are meant to be kept literal here? The single quotes around the expression will keep them from expanding. But also, regex expressions match substrings, so you don't really need the whole url, just enough of it to be sure you're getting only the lines you want. You may want to anchor the match to the start of the line as well.

Code:
sed -i 's|^#Server = ftp://mirror.aarnet.edu.au|Server = ftp://mirror.aarnet.edu.au|g' /etc/pacman.d/mirrorlist

Last edited by David the H.; 01-24-2012 at 09:20 AM. Reason: as stated
 
Old 01-24-2012, 03:41 PM   #5
crabchucker
LQ Newbie
 
Registered: Jan 2012
Location: New Zealand
Distribution: Arch linux, Debian
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for the advice i will try that out later on, i was just following what i found and was not sure if shortening it would work or not or if i didn't write the whole line, so i will see if that works
 
  


Reply

Tags
arch linux, array, bash scripting



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
[SOLVED] How to deal with bash[$style] arrays in a POSIX compliant script? GrapefruiTgirl Programming 8 01-02-2015 11:17 PM
[SOLVED] Pass 2 arrays to a BASH script santhosh_cv Programming 3 11-10-2011 05:23 AM
Adding script file on Bash greatmenon Linux - Software 1 01-21-2006 07:14 AM
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 09:50 AM
bash script - variables & arrays question rblampain Linux - Software 4 09-25-2004 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:27 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration