Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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).
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)
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 11:26 AM.
Reason: grammar
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.
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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.