1

I do a fair bit of work at the command line. When I start my computer up on of the first things I do is open up a terminal window for mysql, and one for the Rails console and usually a third running mongrel. Setting it up every morning is a bit of a drag so I would like to script it. How can I open a terminal window, log into mysql, select my development database and then leave it there at the mysql prompt waiting for me. I know how to execute a mysql statement from bash, I just don't know how to get it to leave the prompt open for me to work with after. Hopefully that is clear!

Update: Combining the two answers below got things working for mysql. Thanks!

Now I am trying to get a gnome-terminal window to stay open running the Rails script/server command so I can watch the output. For some reason the following closes almost immediately:

gnome-terminal  -e "ruby /home/mike/projects/myapp/script/server" &
2
  • What platform are you on? And what do you mean by a terminal? xterm? Commented Dec 17, 2009 at 10:52
  • Oops! Sorry! Running Ubuntu Karmic and opening up gnome-terminal windows. Commented Dec 17, 2009 at 10:55

3 Answers 3

1

xterm provides an option for executing a command:

xterm -e myCommandToLogIntoMysql &

You can put a sequence of such xterm commands into a shell script.

Sign up to request clarification or add additional context in comments.

Comments

0

How can I open a terminal window, log into mysql, select my development database and then leave it there at the mysql prompt waiting for me.

mysql -u user -ppassword -D database_name

Remember not to put space between "-p" and password. Note - this is a bit insecure, as your password is visible in process list so anyone can read it using ps. You can, however, put your MySQL password in ~/.my.cnf file.

Comments

-1

How to correctly open a terminal in your bash script is

#!/bin/bash
    
term=$(/usr/bin/qterminal)

echo "$term"

1 Comment

This doesn’t work if you haven’t installed qterminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.