LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-15-2013, 04:58 PM   #1
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 210

Rep: Reputation: 39
Simple Script Question.


Will a script only call the next "command" after the previous one is completed? Or will it just run them 1 after the other with no let up?

Was going to build a script to install makemkv and handbrake for me all in one shot.
 
Old 12-15-2013, 05:00 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Unless you put a line into the background (with &), then it will wait for each line to finish before going onto the next.
 
Old 12-15-2013, 05:03 PM   #3
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 210

Original Poster
Rep: Reputation: 39
More explanation... Beginning of script would contain an #apt-get (bunch of stuff here)

Would it wait for that to finish before moving on?
 
Old 12-15-2013, 05:33 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Linux Mint 17, Debian 8
Posts: 7,865

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
"More explanation... Beginning of script would contain an #apt-get (bunch of stuff here)

Would it wait for that to finish before moving on?"

yes.

----------------------
Steve Stites
 
Old 12-15-2013, 06:27 PM   #5
David Triebwasser
LQ Newbie
 
Registered: Jul 2011
Location: Richmond, CA
Posts: 7
Blog Entries: 1

Rep: Reputation: Disabled
There are some cases where you want the script to process in order, completing one task before moving onto others. In other cases you may want to run a sub task in the background and even allow it to run outside of your shell session. There's a good explaination of this more complex process here:
http://stackoverflow.com/questions/1...ch-the-session
 
Old 12-15-2013, 07:25 PM   #6
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 210

Original Poster
Rep: Reputation: 39
Think I've got what I'm trying to do. Feedback would be appreciated on where I can improve.

Code:
#!/bin/bash
#Install script for MakeMKV & Handbrake
#Run as root!

#Jason
#2013/12/15	3:08 pm

#####Begin Script#####

#Variables#

MKVUSER=me	#user where files located#
MKVPATH=/home/$MKVUSER/Debian/MakeMKV
MKVOSS=makemkv-oss-1.8.7
MKVBIN=makemkv-bin-1.8.7
HB=hb-trunk

clear

echo "Beginning Compilation & Install"
sleep 2

#get deps#

apt-get install -y libc6-dev libssl-dev libexpat1-dev libavcodec-dev libgl1-mesa-dev libqt4-dev ffmpeg pkg-config build-essential subversion yasm build-essential autoconf libtool zlib1g-dev libbz2-dev libogg-dev libtheora-dev libvorbis-dev libsamplerate-dev libxml2-dev libfribidi-dev libfreetype6-dev libfontconfig1-dev libass-dev intltool libglib2.0-dev libdbus-glib-1-dev libgtk2.0-dev libgudev-1.0-dev libwebkit-dev libnotify-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libappindicator-dev
sleep 2

#oss build & install#

echo "Building MakeMKV OSS Package"
sleep 2
cd $MKVPATH/$MKVOSS
./configure
sleep 1
make
sleep 1
make install
cd ..

#bin build & install#

echo "Building MakeMKV Bin Package"
sleep 2
cd $MKVPATH/$MKVBIN
sleep 1
make
sleep 1
make install
cd ..

#handbrake

echo "Building Handbrake"
sleep 2
cd $MKVPATH/$HB
sleep 1
./configure --enable-ff-mpeg2 --enable-fdk-aac --arch=x86_64 --optimize=speed
cd build
sleep 1
make
sleep 1
make install

#closing notes#

echo "MakeMKV & Handbrake installed. Remember to create a .desktop file for Handbrake"
sleep 4
exit
And made this one to create a shortcut file in the menus.

Code:
#!/bin/bash
#Create Handbrake Launcher	
#Run as user!

#Jason Gibson
#2013/12/15	4:32 pm

#####Begin Script#####

#Variables#

HBUSER=jason
SCPATH=/home/$HBUSER/Desktop/test.desktop
ICONPATH=/home/$HBUSER/Pictures/Icons/Tux.png
APPNAME=Handbrake
APPTYPE=Application
EXEC=ghb
CATEGORY=AudioVideo;
ENCODE=UTF-8
COMMENT=Transcoder

echo "Creating launcher in ~/Desktop"

echo "[Desktop Entry]
Encoding=$ENCODE
Name=$APPNAME
GenericName=$APPNAME
Comment=$COMMENT
Type=$APPTYPE
Exec=$EXEC
Icon=$ICONPATH
Categories=$CATEGORY
Name[fr_FR]=$APPNAME" > $SCPATH

chmod 700 $TESTPATH
mkdir -p /home/$HBUSER/.local/share/applications
cd /home/$HBUSER/.local/share/applications
ln -s $SCPATH

#closing notes#

echo "Shortcut created and added. Enjoy Handbrake!"
These are my first real attempts at scripting.
 
Old 12-15-2013, 07:59 PM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,422
Blog Entries: 9

Rep: Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668Reputation: 3668
there's no need for the sleep commands.
 
Old 12-15-2013, 08:09 PM   #8
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 210

Original Poster
Rep: Reputation: 39
Removed the sleeps, combined the 2 scripts. Had to modify a couple variables to work across the board. Also added more comments for myself so I don't forget how this works. Testing it in a VM right now, internet is slow so still waiting for the package downloads right now.
 
Old 12-16-2013, 04:34 AM   #9
yooden
Member
 
Registered: Dec 2013
Distribution: Debian Wheezy/Jessie # XFCE
Posts: 53

Rep: Reputation: Disabled
Quote:
Originally Posted by Tadaen View Post
Feedback would be appreciated on where I can improve.
If they work, you are fine. Some minor points:
  • I would recommend that you never use bash scripts unless you have a reason to. Use Bourne Shell (sh) instead.
  • Avoid clear(1) and similar commands that mess up the user's screen.
  • Check certain commands for success, eg. the cd's. If they fail, you might end up with something unexpected.
  • The combination of cd $var and cd .. seems to be a mismatch.
 
Old 12-16-2013, 05:16 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,617

Rep: Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367Reputation: 4367
additionally avoid compiling-building by root (only apt-get and make install should be executed by root)!
 
  


Reply


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
simple script question.. mike2010 Linux - Newbie 2 02-08-2009 02:54 AM
Simple script question Elvisclone Programming 2 12-01-2004 10:13 AM
simple bash script question bullium Programming 3 11-01-2004 03:42 PM
Simple VI/Script Question shaggz Linux - General 2 07-05-2003 07:55 PM
simple shell script question mathfeel Linux - General 12 03-06-2003 12:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:27 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration