put an interactive script in background after taking input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting put an interactive script in background after taking input
# 1  
Old 02-15-2008
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  
Old 02-15-2008
...you can append an ampersand ( & ) at the end of the comands you want run in the background
# 3  
Old 02-15-2008
Tools 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  
Old 02-15-2008
Quote:
Originally Posted by epsilonaurigae
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  
Old 02-15-2008
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  
Old 02-15-2008
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  
Old 02-15-2008
Quote:
Originally Posted by epsilonaurigae
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 &

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recording user input from interactive shell script

Hello, I want to start out by saying that I am fairly new to scripting and am looking for someone that can point me in the right direction. Basically what I need is a way to run a interactive script that will prompt users with questions weather that be yes/no or a specific answer.. I want to be... (3 Replies)
Discussion started by: shoutcast
3 Replies

2. Shell Programming and Scripting

Problem in taking input Shell script

I was writing a shell script, where i need to run a command through script and then take input from user and later terminate it. i am not sure how to take input in a proper format immediately after a command. example: below command line is used to import some data in to database (LDAP)... (3 Replies)
Discussion started by: Mridul17
3 Replies

3. Shell Programming and Scripting

Put currently running script into background

Hi All, Suppose I have a script and inside it I want/need to put it into background. I need the script to not react to SIGHUP signals. I tried: #!/bin/bash echo "" > test_disown mypid=$$ echo "PID=$mypid" ( kill -SIGSTOP $mypid jobs > myjobs #disown -h <job-spec> #kill -SIGCONT $mypid )... (6 Replies)
Discussion started by: JackK
6 Replies

4. UNIX for Beginners Questions & Answers

Linux Console for Interactive Input Script

Hi there, How do I enter command to the interactive console. I was able to do it via the first line. What if I have more lines to input into the interactive console from line 3 onwards. Is there a more easier way? (echo -e "load openvas" ; echo -e "openvas_help") | msfconsole ... (4 Replies)
Discussion started by: alvinoo
4 Replies

5. Linux

Not able to put ls -lR command in background

Hi All, i am trying to put ls -lRt command to run in the background but it fails. i continue to get output on screen and didnt get the command prompt right after i put the command in background. command i am using is ls -lRt & i am using bash. Can someone let me know how to... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

6. Shell Programming and Scripting

Interactive script with background

I have script, which need some variable from user and i use below command for this read this script works fine while running without background, but when i run this script in background, it ask first variable then immediately it show below error KSH variable not found please let me... (1 Reply)
Discussion started by: pallvi_mahajan
1 Replies

7. Shell Programming and Scripting

Script to delete files older than x days and also taking an input for multiple paths

Hi , I am a newbie!!! I want to develop a script for deleting files older than x days from multiple paths. Now I could reach upto this piece of code which deletes files older than x days from a particular path. How do I enhance it to have an input from a .txt file or a .dat file? For eg:... (12 Replies)
Discussion started by: jhilmil
12 Replies

8. Programming

Run interactive program in background and grep it

I need to run an interactive program in the background so I can grep it for specific data to use for some logic in a script. There is no quiet or background mode on the program so I plan to redirect a document with commands in it and then to grep the output. This is almost working, except... (1 Reply)
Discussion started by: doonan_79
1 Replies

9. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

10. Shell Programming and Scripting

Interactive ftp get/put

Hi All, I'm trying to get this to work but when I execute it I get the following error ./ftp_upload.sh: line 78: syntax error: unexpected end of file. This was working before I expanded the script and had the here document part directly below within a function. Can anyone spot what I've... (5 Replies)
Discussion started by: darrenm
5 Replies
Login or Register to Ask a Question