LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   making a script that opens terminal and enter commands into that terminal (http://www.linuxquestions.org/questions/linux-general-1/making-a-script-that-opens-terminal-and-enter-commands-into-that-terminal-358651/)

Cinematography 08-30-2005 07:45 PM

making a script that opens terminal and enter commands into that terminal
 
Is there a way to make a script that opens your terminal and enters a series of commands (like mkdir, chown, etc) into that terminal?

mrosati 09-01-2005 04:54 AM

it is possible to make a script that performs directly the commands you have to enter in a console. Can you be more specific :) ? What do you have to do with this script?

Cinematography 09-03-2005 12:23 PM

Quote:

Originally posted by mrosati
it is possible to make a script that performs directly the commands you have to enter in a console. Can you be more specific :) ? What do you have to do with this script?
Because I'm a lazy fool, I wanted to make a script that would open a terminal and enter some of the commands, or a series of commands, that I enter a lot. That's all.

mrosati 09-03-2005 01:01 PM

a script is a list of commands for a shell. you can do 2 things:
1) edit your script. no matter what you write in it, just write your command-list correctly.
2) the script must now be "chmoded" as executable (chmod 755 <scriptname>)
3) now run your script, you can do this in 2 ways:
3.1) double click your script icon (kde)
3.2) from a shell, simply (./<scriptname, supposing your working directory is the same where the script is located)

it is not useful (either i don't know if it is possible) to make a script that runs a shell and then "puts" a sequence of commands in it. all these tasks are performed simply by the script.

if you want to be helped in writing the script you can ask me everything you want.

julia79 12-15-2008 04:31 AM

Quote:

Originally Posted by mrosati (Post 1834208)
a script is a list of commands for a shell. you can do 2 things:
1) edit your script. no matter what you write in it, just write your command-list correctly.
2) the script must now be "chmoded" as executable (chmod 755 <scriptname>)
3) now run your script, you can do this in 2 ways:
3.1) double click your script icon (kde)
3.2) from a shell, simply (./<scriptname, supposing your working directory is the same where the script is located)

it is not useful (either i don't know if it is possible) to make a script that runs a shell and then "puts" a sequence of commands in it. all these tasks are performed simply by the script.

if you want to be helped in writing the script you can ask me everything you want.



Hello,

I would want to write a script which open a new terminal and here , in the new terminal opened, to login using ssh on other machine. Do you think that it is possible?

Thank you,
Iulia

i92guboj 12-15-2008 10:45 AM

That entirely depends on the terminal you use.

There's no easy way to just "dump" commands into a terminal.

However, most terminals can use -e to run a given script. So, my advice would be to save the commands you want to write into a shell script, then chmod u+x it, and then you can just do this

Code:

xterm -e /path/to/yourscript.sh

mrclisdue 12-15-2008 12:49 PM

Quote:

Originally Posted by julia79 (Post 3375934)
Hello,

I would want to write a script which open a new terminal and here , in the new terminal opened, to login using ssh on other machine. Do you think that it is possible?

Thank you,
Iulia

Sure it is:
Code:

xterm -e ssh <remote_machine>
Depending on how you've setup ssh, you'll either now be logged into the remote_machine, or you'll have a terminal with a prompt for username/password on the remote.

If you want it scripted

Code:

#!/bin/bash
#open new terminal window with ssh login to machine_name
Terminal -e ssh <remote_machine>

cheers,

i92guboj 12-15-2008 01:23 PM

Quote:

Originally Posted by mrclisdue (Post 3376397)
If you want it scripted

Code:

#!/bin/bash
#open new terminal window with ssh login to machine_name
Terminal -e ssh <remote_machine>

cheers,

I'd rather alias it. I am reluctant to make a script for a oneliner unless I have a good reason to.

You can alias it and put it into ~/.bashrc and/or ~/.bash_profile (or whatever the rc files for your shell are). For bash it would be like:

Code:

alias xssh='xterm -e ssh user@host'
If you need to parametrize you can use a function instead

Code:

function xssh() {
  xterm -e ssh "$1"
}

Then use it from bash like this

Code:

xssh user@host

julia79 12-16-2008 10:34 AM

Quote:

Originally Posted by mrclisdue (Post 3376397)
Sure it is:
Code:

xterm -e ssh <remote_machine>
Depending on how you've setup ssh, you'll either now be logged into the remote_machine, or you'll have a terminal with a prompt for username/password on the remote.

If you want it scripted

Code:

#!/bin/bash
#open new terminal window with ssh login to machine_name
Terminal -e ssh <remote_machine>

cheers,

Thank you very much. It was very helpfully for me.

Have a gread day,
Iulia


All times are GMT -5. The time now is 08:55 AM.