Register
It is currently Thu Aug 21, 2014 3:58 pm

Install Script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Wed Sep 01, 2010 8:45 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
I've managed to kill my linux machine so will need to re-install the os again however after that i'd like to be able to run an install script to add software/configs etc.

So something like

Code:
echo "Installing software"
apt-get -y install etc etc
echo "Software Installed"


How do I make the script wait for the above process to finish before starting the next one? I saw something about wait $! would this do it?

I've just tried to make a test network config section

Code:
#!/bin/bash
rm /etc/network/interfaces
touch /etc/network/interfaces
echo "Configuring Network"
echo "# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback"

> /etc/network/interfaces
echo "Network Setup Complete"


It creates the interfaces file but it's blank? probably to do with how i've done the > or using " any ideas?

Also i'll need to configure install various modules will I have to 'wait' after each one ie

Code:
apt-get -y install libusb-dev
wait
cpan -fi Bundle::CPAN
wait
cpan -fi ExtUtils::MakeMaker
wait
cpan -fi Inline::MakeMaker
wait
cpan -fi Device::USB


Top
 Profile  
 PostPosted: Wed Sep 01, 2010 11:36 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
BrianUK wrote:
Code:
echo "Installing software"
apt-get -y install etc etc
echo "Software Installed"


How do I make the script wait for the above process to finish before starting the next one? I saw something about wait $! would this do it?


Why would you assume that the process in your script will return your prompt before it is done? Like all (unix) commands, you will only get your commandprompt back after a command or process is complete. The only exception is when you specifically start a process as a background process.

BrianUK wrote:
Code:
#!/bin/bash
rm /etc/network/interfaces
touch /etc/network/interfaces
echo "Configuring Network"
echo "# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback"

> /etc/network/interfaces
echo "Network Setup Complete"


It creates the interfaces file but it's blank? probably to do with how i've done the > or using " any ideas?


Try putting the output redirection (> /etc/network/interface) on the same line where your echo command ends.
Putting it on a new line will output 'nothing' to your filename, just as you request.

BrianUK wrote:
Also i'll need to configure install various modules will I have to 'wait' after each one ie

Code:
apt-get -y install libusb-dev
wait
cpan -fi Bundle::CPAN
wait
cpan -fi ExtUtils::MakeMaker
wait
cpan -fi Inline::MakeMaker
wait
cpan -fi Device::USB


Again, why are you assuming that these commands would be run simultaniously instead of one after the other? The 'wait' command is only used to wait for processes that have specifically been started as a background process. As you have not started these as background processes, each command will only start after the previous one is finished.


Top
 Profile  
 PostPosted: Wed Sep 08, 2010 1:16 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
indeed I was clearly having a 'moment' and not thinking =)) , thanks for the info anyway

Is it possible to execute a script between certain lines as testing the install script from the 'top' every time obviously throws up lots of errors so i'd like to test each section at a time without having to # it out.

ie install line23 to line 45


Top
 Profile  
 PostPosted: Wed Sep 08, 2010 3:36 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
easily:
Code:
$(sed -n 23,45p install)


Top
 Profile  
 PostPosted: Wed Sep 08, 2010 5:54 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
For complicated tasks with many steps, I usually use make. :-B


Top
 Profile  
 PostPosted: Wed Sep 08, 2010 2:03 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
BrianUK wrote:
Is it possible to execute a script between certain lines as testing the install script from the 'top' every time obviously throws up lots of errors so i'd like to test each section at a time without having to # it out.

ie install line23 to line 45


If you only want to execute certain parts of your script, I suggest putting them in functions and execute only the functions you want to.

Code:
#!/bin/bash

function run_me {
  echo "I'm doing something fun";
}

function run_me_not {
  echo "I'm st00pid";
}

run_me


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP