LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-19-2007, 01:52 PM   #1
basd
Member
 
Registered: Apr 2002
Location: Riverside CA USA
Distribution: SuSE 11
Posts: 83

Rep: Reputation: 15
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.
 
Old 09-19-2007, 02:15 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,430

Rep: Reputation: 83
Is this what you want?
Code:
xterm -e xeyes
Happy Penguins!
 
Old 12-16-2007, 04:15 PM   #3
everyday
LQ Newbie
 
Registered: May 2006
Posts: 8

Rep: Reputation: 0
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.
 
Old 01-26-2008, 05:03 PM   #4
basd
Member
 
Registered: Apr 2002
Location: Riverside CA USA
Distribution: SuSE 11
Posts: 83

Original Poster
Rep: Reputation: 15
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
 
Old 01-26-2008, 08:51 PM   #5
basd
Member
 
Registered: Apr 2002
Location: Riverside CA USA
Distribution: SuSE 11
Posts: 83

Original Poster
Rep: Reputation: 15
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 ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify bash to allow to execute some specified commands only ? nitin_ucer Linux - Security 5 08-16-2007 03:33 PM
Run one script, but execute commands at the same time Micro420 Programming 8 07-18-2007 12:05 AM
bash - execute commands on a remote machine capture results, etc dkrysak Programming 1 11-18-2005 01:50 PM
Execute bash commands from web page solomage Linux - Software 1 10-07-2004 10:54 AM
BASH scripting; su to user, commands after dont execute Zero-0-Effect Programming 4 06-07-2004 11:09 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration