3

My Script is having 2 command-line arguments and then just couple of questions, after these questions the script will run for itself, I'm able to pass the command-line argument by just doing,

-bash-3.2$ nohup ./Script.sh 21 7
nohup: appending output to `nohup.out'

-bash-3.2$

Anyway to add the answers of these to-be-asked-questions with nohup?

2
  • What OS do you use? Is your nohup from coreutils?
    – cuonglm
    Commented Sep 4, 2014 at 5:00
  • -bash-3.2$ uname -a Linux -------------------------------- 2.6.18-238.5.1.el5 #1 SMP -----------05:52:39 --- ---- x86_64 x86_64 x86_64 GNU/Linux Commented Sep 4, 2014 at 5:23

1 Answer 1

4

Instead of using nohup, you could have your script ask these questions interactively and then background and disown the remainder of whatever else it has to do.

Example

$ more a.bash 
#!/bin/bash

read a
echo "1st arg: $a"
read b
echo "2nd arg: $b"

(
echo "I'm starting"
sleep 10
echo "I'm done"
) &
disown
Sample run:
$ ./a.bash 
10
1st arg: 10
20
2nd arg: 20
I'm starting
$
Check on it:
$ ps -eaf|grep a.bash
saml      6774     1  0 01:02 pts/1    00:00:00 /bin/bash ./a.bash
saml      6780 10650  0 01:02 pts/1    00:00:00 grep --color=auto a.bash
10 seconds later:
$ I'm done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .