LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2009, 04:09 AM   #1
bergman
Member
 
Registered: Jan 2009
Distribution: slackware 12.1 (kernel 2.6.24.5-smp)
Posts: 39

Rep: Reputation: 17
keeping xterm open?


hello,

I have a commandline based program which I run in an xterm, called from a fluxbox menu (so I dont manually open the xterm myself).

Code:
xterm -e program
The problem is that the program needs to be run twice with different options, but the xterm closes after each program and option completes, and it has to open a new xterm to execute the next command.

Is there a way to keep an xterm open so that a program can run multiple commandlines in that one xterm instance?

like this:

Code:
1. call xterm
2. execute 'program -option 1'.
3. execute 'program -option 2' (in same xterm instance.)
4. keep xterm open

Last edited by bergman; 02-24-2009 at 04:10 AM.
 
Old 02-24-2009, 08:17 AM   #2
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Is this a bash script or what? What is this "program" supposed to do and how? It would be nice if we could see the source.
 
Old 02-24-2009, 11:40 AM   #3
bergman
Member
 
Registered: Jan 2009
Distribution: slackware 12.1 (kernel 2.6.24.5-smp)
Posts: 39

Original Poster
Rep: Reputation: 17
Hello Alan,

The program is 'rkhunter'.

http://rkhunter.sourceforge.net/

It is a program for detecting rootkits, and run's in console or terminal. I would like to run it in an Xterm.

There two commands I need to run together:

Code:
rkhunter --update
secondly:

Code:
rkhunter -c

I would like to run these two commands in the same instance of Xterm.

the problem is that I call xterm from another program (fluxbox menu), and it opens xterm and executes the first of the commands, but then once that has finished, the Xterm closes, so I am unable to run the second command (in the same Xterm window).

Last edited by bergman; 02-24-2009 at 11:43 AM.
 
Old 02-24-2009, 12:46 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hello Bergman

I've been looking for a way to do what you want to do for some time; it may not be possible (why not? IIRC it was possible on HP-UX and Solaris).

You could write a script to do steps 2 and 3 and leave the terminal open while the user reads the output. The reader would unfortunatel not then ba able to do anything except close the terminal. You could call the script from the fluxbox menu with xterm -e myscript

The script could be something like (not tested -- just to give the idea)

Code:
#! /bin/bash
rkhunter --update
rkhunter -c
read
Best

Charles
 
Old 02-24-2009, 12:47 PM   #5
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
This is just a quick answer since I don't use xterm,rkhunter and Fluxbox but you can see if it works.Why don't you make "one command" out of this two that you now have;
Code:
rkhunter --update && rkhunter -c

Last edited by alan_ri; 03-05-2009 at 12:26 PM. Reason: grammar
 
Old 02-24-2009, 02:49 PM   #6
bergman
Member
 
Registered: Jan 2009
Distribution: slackware 12.1 (kernel 2.6.24.5-smp)
Posts: 39

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by catkin View Post
Hello Bergman

I've been looking for a way to do what you want to do for some time; it may not be possible (why not? IIRC it was possible on HP-UX and Solaris).

You could write a script to do steps 2 and 3 and leave the terminal open while the user reads the output. The reader would unfortunatel not then ba able to do anything except close the terminal. You could call the script from the fluxbox menu with xterm -e myscript

The script could be something like (not tested -- just to give the idea)

Code:
#! /bin/bash
rkhunter --update
rkhunter -c
read
Best

Charles
Thankyou Charles, the script worked.

I didnt think of passing a script to xterm

Code:
xterm -e rkhunter --update && rkhunter -c
unfortunately the above command doesnt work.

it runs 'rkhunter --update' in an xterm, but when the update has finished, xterm closes. I think that the 'rkhunter -c' part is being executed because my cpu is at 100%, but its in the background and Im unable to view it.
 
Old 02-24-2009, 05:56 PM   #7
GazL
Senior Member
 
Registered: May 2008
Posts: 4,090
Blog Entries: 1

Rep: Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538
You could put your rkhunter commands in a rc file,
Code:
cat > ~/.rkhunter.bashrc <<_EOF
[ -f ~/.bashrc ] && source ~/.bashrc 
rkhunter --update
rkhunter -c
_EOF
And then call it with something along the lines of this,
Code:
xterm  -e "/usr/bin/bash --rcfile ~/.rkhunter.bashrc"
Unlike catkin's example above which uses the read to delay the xterm closing, this leaves you with a fully operational bash session to work in.

Don't forget to source your existing ~/.bashrc into your rkhunter.bashrc file if you have one as the --rcfile option will mean it won't get run otherwise.
 
Old 02-24-2009, 08:02 PM   #8
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Actually,what I had in mind was something like;
Code:
xterm -e "bash /path/to_the/script"
and that's something close to what GazL said and he is right.
 
Old 02-25-2009, 06:14 AM   #9
bergman
Member
 
Registered: Jan 2009
Distribution: slackware 12.1 (kernel 2.6.24.5-smp)
Posts: 39

Original Poster
Rep: Reputation: 17
thanks

I didnt consider the possibility that I may need the prompt back at some point.

Could you explain what this part of the script does? I notice that when I look into the script after creation, this part is missing?

Code:
cat > ~/.rkhunter.bashrc <<_EOF

Last edited by bergman; 02-25-2009 at 06:42 AM.
 
Old 02-25-2009, 07:35 AM   #10
GazL
Senior Member
 
Registered: May 2008
Posts: 4,090
Blog Entries: 1

Rep: Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538
Quote:
Originally Posted by alan_ri View Post
Actually,what I had in mind was something like;
Code:
xterm -e "bash /path/to_the/script"
and that's something close to what GazL said and he is right.
That will only work if the script doesn't end alan, the bash process will exit when it hits EOF on the script. it's actually little different than,
Code:
xterm -e "/path/to_the/script"
You can actually use multiple commands within the -e option as xterm just passes that string to the shell, so any of the following may do what bergman is looking for.

Code:
xterm -e " command1 ; command2 ; read -p 'Press enter to close window'"

xterm -e " command1 ; command2 ; sleep 3650d "

xterm -e " ( command1 ; command2 ) 2>&1 | tail -f "

xterm -e " command1 ; command2 ; bash"
I'm not sure off hand how to make the sleep in the second example be infinite so I just used 3650days, just use a value that's going to be long enough for you.

The final example is very similar to what happens with my --rcfile suggestion, except the shell you get dumped into on completion won't be the same one that your commands ran in. It'll be a sub process.
 
Old 02-25-2009, 07:43 AM   #11
GazL
Senior Member
 
Registered: May 2008
Posts: 4,090
Blog Entries: 1

Rep: Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538
Quote:
Originally Posted by bergman View Post
thanks

I didnt consider the possibility that I may need the prompt back at some point.

Could you explain what this part of the script does? I notice that when I look into the script after creation, this part is missing?

Code:
cat > ~/.rkhunter.bashrc <<_EOF
Ah sorry, that's not actually part of the script, it was me trying to be helpful. hehe. If you cut and paste those commands directly into your terminal it'll create that .rkhunter.bashrc file for you.

It's called a 'Here Document'
Basically, what it's saying is:

run cat redirecting the output (>) to ~/.rkhunter.bashrc
taking the input from the following lines until you find the characters _EOF (<<_EOF)

If you look at man bash and search for "Here Documents" it'll explain it all in gory detail. They're a very useful tool at times.
 
Old 02-25-2009, 09:18 AM   #12
bergman
Member
 
Registered: Jan 2009
Distribution: slackware 12.1 (kernel 2.6.24.5-smp)
Posts: 39

Original Poster
Rep: Reputation: 17
oh I see.

Thanks again, Ive learned some interesting things from this thread

Last edited by bergman; 02-25-2009 at 09:26 AM.
 
Old 02-25-2009, 10:43 AM   #13
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by GazL View Post
You could put your rkhunter commands in a rc file,
Code:
cat > ~/.rkhunter.bashrc <<_EOF
[ -f ~/.bashrc ] && source ~/.bashrc 
rkhunter --update
rkhunter -c
_EOF
And then call it with something along the lines of this,
Code:
xterm  -e "/usr/bin/bash --rcfile ~/.rkhunter.bashrc"
[snip]
A thousand "thank you"s GazL

I've been looking for a way to achieve that functionality for ages (and not understanding why the graphical terminal programs don't facilitate it).

Adapting your technique for GNOME on ubuntu 8 only required changing xterm to gnome-terminal and /usr/bin/bash to /bin/bash.

Sweet! Best

Charles
 
Old 02-25-2009, 12:16 PM   #14
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Quote:
Originally Posted by GazL View Post
That will only work if the script doesn't end alan, the bash process will exit when it hits EOF on the script. it's actually little different than,
Code:
xterm -e "/path/to_the/script"
You have to know that I had a ~/.bashrc file in mind.One can use 15 bashrc files instead the default one and load a new version of Bash in the current terminal whenever one wants and xterm will not close when the script is executed.The script doesn't have to end with _EOF and I didn't have your script in mind.My script would look a little different if I needed to make one.Since you mentioned it;will you explain where you see the difference between;
Code:
xterm -e " command1 ; command2 ; bash"
and
Code:
xterm -e "bash /path/to_the/script"
if you have in mind that script is made only from command 1 and command 2.

...and yes,
Code:
xterm -e "/path/to_the/script"
is very different then
Code:
xterm -e "bash /path/to_the/script"
 
Old 02-25-2009, 02:06 PM   #15
GazL
Senior Member
 
Registered: May 2008
Posts: 4,090
Blog Entries: 1

Rep: Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538Reputation: 1538
Quote:
Originally Posted by alan_ri View Post
Since you mentioned it;will you explain where you see the difference between;
Code:
xterm -e " command1 ; command2 ; bash"
and
Code:
xterm -e "bash /path/to_the/script"
In the first example you're passing 3 commands to xterm. the third of which is another instance of bash which will keep the xterm open.
In the second you're passing 1 command to xterm which is bash and providing bash with an input script file to run. When bash gets to the end-of-file in that input file it will exit, which in turn will cause the xterm to exit. That doesn't happen in the first example as the final bash doesn't receive and end-of-file.

In the context of what the original poster was trying to achieve (i.e. open a xterm and run some commands in it but leave it open) the difference is clear. one will exit on completion and the other remains open.

Having said that, it's still a bit of a hack, and using the --rcfile parameter could probably be considered more correct.
 
1 members found this post helpful.
  


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
xterm -display remote:0.0 Can't open display - xterm from tru64 to debian 3.1 loopy69 Linux - Software 2 04-01-2008 07:54 PM
LXer: On keeping an open mind LXer Syndicated Linux News 1 03-03-2007 10:20 PM
keeping the terminal window open NNP Linux - General 1 09-02-2005 12:08 AM
keeping xterm awake LancerNZ Linux - Newbie 1 05-06-2005 08:41 PM
Keeping windows open martinpanda Programming 0 01-25-2002 04:46 PM


All times are GMT -5. The time now is 07:22 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration