LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-18-2011, 07:15 AM   #1
dann_radkov
Member
 
Registered: Sep 2011
Posts: 52

Rep: Reputation: Disabled
Bash script execution


Hey Folks,
I need to create a bash script that will launch 3 separate commands one after the other. I have decided to put in a sleep command between them so that it waits for a certain amount of time(since I am not 100% sure commands can be executed simultaneously or all at once). The output of command1 requires some time to process.So does the output of command2 and command3.

Do you consider this appropriate :

#!/bin/bash
cd /usr/sbin
command1(which performs analysis)
*here it asks for credentials*
Then it executes the command.

sleep (say 100 just in case )

command2(performs staging)
*here it asks for credentials*

sleep 100

command3(performs install)
*here again asks for creds*

Perhaps I can implement the username/pass as a variable.
VARIABLE1=username
VARIABLE2=password

Please let me know if you have any suggestions.
 
Old 10-18-2011, 07:22 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,974

Rep: Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179
You are concerned about the processing ... do any of the commands require the other to complete prior to running or possibly interact with the same data so there could be a locking issue?

If not, then you should be able to launch each one in turn.
 
1 members found this post helpful.
Old 10-18-2011, 07:32 AM   #3
dann_radkov
Member
 
Registered: Sep 2011
Posts: 52

Original Poster
Rep: Reputation: Disabled
Yes they should be launched in this order.Each command must complete before the other one is executed.Thats why I included the sleep.
Question is how do I define the variables for uname and pass and where in the script in particular?
 
Old 10-18-2011, 08:05 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,974

Rep: Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179
Well as each relies on the previous I would probably use the && operator between each. This way only on successful completion of the previous command will the next execute.

As for setting variables, you could try looking into the expect command but of course it is inherently dangerous to have passwords in plain text form in a file.
So I would try and use something like sudo to elevate privileges of the user so passwords are not required.
 
Old 10-18-2011, 08:08 AM   #5
dann_radkov
Member
 
Registered: Sep 2011
Posts: 52

Original Poster
Rep: Reputation: Disabled
But note that the system is asking for a uname/password which corresponds to another application.Root uname/pass just wont`do.Thats why I am concerned.
 
Old 10-18-2011, 09:46 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,974

Rep: Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179
Then its back to investigating expect.
 
  


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
[SOLVED] Bash script execution error dann_radkov Linux - Newbie 4 09-13-2011 03:15 PM
Detect bash script source vs. direct execution Jessard Programming 11 11-30-2010 06:43 AM
[SOLVED] Getting duration of execution in bash Himilhil Linux - Software 4 11-04-2009 02:21 AM
BASH: open console on script execution Quis Programming 2 02-07-2006 09:41 AM
Execution options in bash eremit Programming 6 03-28-2005 10:00 PM

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

All times are GMT -5. The time now is 02:49 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
Open Source Consulting | Domain Registration