LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   bash - how to launch a console window via script and execute commands in it? (http://www.linuxquestions.org/questions/programming-9/bash-how-to-launch-a-console-window-via-script-and-execute-commands-in-it-585873/)

basd 09-19-2007 01:52 PM

bash - how to launch a console window via script and execute commands in it?
 
Hi,

I'm not that familiar with bash scripting.

I have a script that launches via MIME from Firefox, with a custom extension. It works okay.

The script also works to open a console and run the script manually from a commandline. But, I want the script itself to open the console and then execute the commands within the console.

I have been able to have a single command open in a konsole window like this:

konsole gpg [etc.]

I think I can do this:

konsole echo "what the heck?"

But I want to do this:

konsole
echo "what the heck"
echo "i have no idea what I'm doing"
echo "so this window will close."
gpg -e [etc]

(Konsole could be replaced by xterm or whatever. Konsole is from KDE.)

Of course, as you know, the above script wouldn't work because the console opens, closes, and then the echo commands all happen without writing to a console at all so I won't see them.

I want the execution to happen in the konsole window.

Any thoughts? I've browsed a bit through various bash and linux scripting manuals, but I haven't been able to find what I am looking for.

Thanks.

kaz2100 09-19-2007 02:15 PM

Is this what you want?
Code:

xterm -e xeyes
Happy Penguins!

everyday 12-16-2007 04:15 PM

even now 2 years later you still the man!

execute or run script in a new terminal bash or xterm.

even from a menu. I entered this into the fluxbox menu and a new terminal / bash window opens and the script is run - no need to even cd to the folder and seemingly no need for a & at the end either. the & symbol at the end is supposed to keep it running and then keep running the next commands when in a list of commands or a script. ie..

cd home/blabla/.runme1.sh &
cd mousepad /usr/blabla.txt &
cd another/place/script.sh
sudo mousepad /etc/fstab

So the first 2 lines of this script will run the script and then move on to the next line but the 3rd line hasn't got the 'and' (&) symbol so waits until that command is complete until continuing.

basd 01-26-2008 05:03 PM

how to pause script execution -- new problem, same project
 
Well, all worked out while I was using KDE3.5 and I was able to create the script I wanted.

Now all of a sudden, along comes KDE4.0 and my script won't work anymore, which seems strange to me, since presumably bash execution does not relate to the desktop software?

So, as far as I can tell, when I am running KDE4.0, this script does not "pause" to wait for the next command. That is, apparently the "odt" file is re-encrypted and removed before soffice actually executes.

Whereas, when I am running KDE3.5 I can unencrypt the file via gpg, the script launches OpenOffice to edit the file -- and waits until I exit OpenOffice to re-encrypt and remove the odt file.

How do I get my script to wait until one task completes before commencing the next task?

Thx.


Anyway, here's my script:

#!/bin/bash
# launchodt
#
#script to launch encrypted odt file
#
if [ -e "$1.odt" ]
then
echo "file exists"
else
echo "file don't exist"
konsole -e gpg -o $1.odt $1
fi
if [ -e "$1.odt" ]
then
soffice -writer $1.odt
gpg -e -r client $1.odt
fi
if [ -e "$1.odt.gpg" ]
then
rm $1.odt
mv $1.odt.gpg $1
else
echo "File did not encrypt!!!"
fi

basd 01-26-2008 08:51 PM

partially solved (launch terminal and execute via bash script)
 
Okay, I ran my script from another script that launches it in x-term. So, then I see an error that indicates a "session manager" failure and that bash failed to open a network socket. So, that would explain why the script simply forges ahead. This would seem to be a KDE4.0 problem, since I don't have the same thing in KDE3.0. Some other observations are that when I launch the script from the Dolphin file manager, everything runs extremely slowly (including OpenOffice save & exit). When I launch the script from the Konqueror filemanager, everything executes quickly. Just a bit of trivia someone else might be interested in.

I put a "read" command into my script, and so I can pause execution until a manual response.

But, this is not an elegant solution.

So, anyone with some better suggestions for automating the process?

Also, it's not clear to me why gpg will not open a dialog box when the script calls it without a terminal, but when I call gpg via a terminal command, then I get both an open terminal >and< a separate (more attractive) dialog box ...


All times are GMT -5. The time now is 10:04 PM.