LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   opening new bash tabs or consoles from a script (https://www.linuxquestions.org/questions/programming-9/opening-new-bash-tabs-or-consoles-from-a-script-199004/)

Nice-n-Slow 06-29-2004 03:56 AM

opening new bash tabs or consoles from a script
 
I have a very simple script that runs a program called streamripper. What it does is record streaming audio. One of the nice features about the command line version of this program is that you can see what is being recorded in your console.
The tricky part is that I like to start several copies of this program in different tabs of a tabbed Konsole session. How can I make a script that will open each instance in its own tab?
Alternately, if Konsole tabs are problematic how about running them in their own shells?
Thanks

fluppi 06-29-2004 08:02 AM

To open a Xterminal window and give it a job, type "xterm -e sleep 5 &".

But I have doubts to open an audio device more than once ?

Hth
Fluppi

Nice-n-Slow 06-29-2004 01:36 PM

I think I better be a little more specific about how this works. I tried your advice in a way, but it didn't seem to do what I was looking for. Let me elaborate on how this goes.

Oh yeah, and just to keep things straight, the program itself has nothing to do with any audio devices. It just happens to be recording an audio stream but it may as well be a log file. All the program does is record bits to the disk. There is no audio device to be concerned with. In fact, I can run multiple instances by opening separate terminals and running them manually so it is definitely possible to do. There is no question that it works, I just want to start it more quickly.

The script is very simple, it is as follows:
Here's an example of a single script that would start recording in a console window.


Code:

#!/bin/bash
/path/program_name options stream_URL output_path

Now, when I invoke the name of that simple one line bash script, it will start the program in a console and the console will slowly fill up with data showing what was recorded. Again, this is not much different than a log file.

Manually, it is not a problem to start multiple consoles or tabbed konsole windows and then type in a series of different streams. Having multiple instances is absolutely not a problem.

However, when I want to put all of these little one line scripts into a longer one so that I don't have to manually open so many console windows and type the names of these one-line scripts, that's where I run into problems.

Here is what I tried to do.


Code:

#!/bin/bash
/path/program_name options stream_URL-1 output_path-1
/path/program_name options stream_URL-2 output_path-2
/path/program_name options stream_URL-3 output_path-3
/path/program_name options stream_URL-4 output_path-4

But naturally, what happen is the first one starts to run and since it doesn't end, the other ones never start.

So, I took your advice and added the command you mentioned like so. . .


Code:

#!/bin/bash
xterm -e sleep 5 &
/path/program_name options stream_URL-1 output_path-1
xterm -e sleep 5 &
/path/program_name options stream_URL-2 output_path-2
xterm -e sleep 5 &
/path/program_name options stream_URL-3 output_path-3
xterm -e sleep 5 &
/path/program_name options stream_URL-4 output_path-4

But, although that popped up a dialogue that said "sleep" that quickly disappeared, it didn't change the basic problem of starting the subsequent steams in new consoles.

jlliagre 06-29-2004 02:10 PM

xterm -e "/path/program_name options stream_URL-1 output_path-1"&
would do better

Nice-n-Slow 06-30-2004 07:58 AM

Yeska! Thanks, that is sweet. I'm so impressed.
And not that it is essential, but how about other types of terminals like a kshell and how about tabbed instead of each in its own window?
It's not important really, but out of curiosity I'd be interested.

Nice-n-Slow 07-12-2004 07:39 AM

Well, I'm still not quite satisifed. I mean xterm is pretty good, but if the app ends it just shuts down. The problem with that is if I start a script with ten terminals and number seven goes down, I have to go back, find out which job terminal seven was on and then restart it manually.

In contrast, if I open up say tabbed Konsoles and manually enter the jobs, then when one goes down I can just hit the up key and restart without having to be concerned about figuring out which one it was.

What I'd really like to know is how to script up a bunch of virtual terminals on the command line as opposed to X. My system only offers four virtual terminals and I'm not sure how to increase that number, map them to hot keys and then make use of them in a script, but that would be the ultimate.

Nice-n-Slow 07-12-2004 09:10 AM

Oops.
I forgot. I wasn't posting just to share my desires for a more refined technique. I was going to share another technique I came across and, in fact, after I posted I realized that it contained a solution to part of my problem.
The closest I've come so far is a script with a line like this.

konsole --noclose -e program_to_execute

Note, don't use quotes if you try this one. Apparently xterm wanted quotes, but konsole doesn't.

Like anybody is really interested, but I thought I'd put it up here for future reference.

jlliagre 07-12-2004 09:25 AM

I can't help on the kconsole issue, in fact, I don't think there is a way to open a kconsole tab programmatically by say an escape sequence.

However, if your ten scripts need to run non stop, what about launching persistant xterms restarting your command like:

cmd1 shell script content:
Code:

while true
do
  /path/program_name options stream_URL-1 output_path-1
  echo -n "Program STOPPED, press return to restart it"
  read foo
done

launched by:
Code:

xterm -e /path/cmd1&
etc...


All times are GMT -5. The time now is 11:18 PM.