The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script is taking more than 3 hrs to execute nvuradi Shell Programming and Scripting 2 11-18-2007 11:02 PM
Wrap Interactive Script meskue Shell Programming and Scripting 0 06-23-2006 06:21 PM
script to performm interactive ftp prash_b SUN Solaris 1 05-09-2006 08:21 AM
Giveing input for BACKGROUND process g_s_r_c Shell Programming and Scripting 2 09-06-2004 12:14 PM
Capture output from interactive script MizzGail Shell Programming and Scripting 6 04-04-2002 05:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-15-2008
epsilonaurigae epsilonaurigae is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
put an interactive script in background after taking input

i am trying to find a way to put an interactive script in the background after taking input from the user

a few test lines i was trying:

date
echo "Enter location"
LOCATION=
read LOCATION
sleep 100
sleep 200
date

for this small example i want the script to as the user for the location. once the location is supplied then it should execute the subsequent commands in the script in the background and return control of the tesrminal to the user.

i am a newbie to shell scripting. please help.
  #2 (permalink)  
Old 02-15-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
...you can append an ampersand ( & ) at the end of the comands you want run in the background
  #3 (permalink)  
Old 02-15-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool What are you trying to accomplish?

Take input.. for example a location code
wait (or, submit to background)

After you input, couldn't you just call another script/program (and put that in the background if need be)?

After input of data, to pass data to other program you could:
1) export the variable
2) pass the variable as a parameter
3) write the variable to a file, and read in called program

Perhaps a little more detail on what you are trying to do.
  #4 (permalink)  
Old 02-15-2008
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by epsilonaurigae View Post
i am trying to find a way to put an interactive script in the background after taking input from the user

a few test lines i was trying:

date
echo "Enter location"
LOCATION=
read LOCATION
sleep 100
sleep 200
date

for this small example i want the script to as the user for the location. once the location is supplied then it should execute the subsequent commands in the script in the background and return control of the tesrminal to the user.

i am a newbie to shell scripting. please help.
Press CTRL-Z
next:
bg<enter>
  #5 (permalink)  
Old 02-15-2008
epsilonaurigae epsilonaurigae is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
thanks to all.

System Shock -- & doesnt work as when i supply the location it gives an error "Execute permission denied", in other words it doesnt read it as the input to the script but a separate command itself

joeyg -- your idea makes sense. but i was looking for something like a single script way of achieving this.

sb008 -- your idea needs manual intervention. i am giving this to a few non-tech folks who will input what they have to. i cant expect them to find the pid and put it in bg, hence the question.

really appreciate you guys taking time to answer.
  #6 (permalink)  
Old 02-15-2008
fimblo fimblo is offline
Registered User
  
 

Join Date: Feb 2008
Location: stockholm sweden
Posts: 31
place the stuff you want done in the background inside parens, and add the ampersand at the end of the block, like so:

Code:
date
echo "Enter location"
LOCATION=
read LOCATION
(
 sleep 3
 date
) &
  #7 (permalink)  
Old 02-15-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
Quote:
Originally Posted by epsilonaurigae View Post
thanks to all.

System Shock -- & doesnt work as when i supply the location it gives an error "Execute permission denied", in other words it doesnt read it as the input to the script but a separate command itself
.
If you create a script that takes input and then executes a command and puts it in the background, it works.
Say you touch a file in /tmp named hello, then you take a file name, pass it to a find command, and put that find command in the background...
Code:
# touch /tmp/hello
# cat script
echo "Enter file name"
read FILE
find / -name $FILE &
After you run the script, you hit the enter key, and you get your prompt back while the find command runs in the background. As for the error you are getting, permission denied means you don't have enough permissions to do something, but I can't tell what it is from what you posted.

Another way of doing it, would be to take the input on the command line, rather than a read command, then you can just put the whole thing in the background, like:

Code:
# cat script
LOCATION=$1

# ./script Arizona &
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0