[opensuse] ssh to a machine, run bash with some commands, keep bash running?
I want to be able to do something like this: me@hostA> ssh user@hostB somecommand Where the end result is that somecommand runs and _I am still logged in to hostB_, running bash as if I had done these commands: me@hostA> ssh user@hostB user@hostB> somecommand user@hostB> I want "somecommand" to set up some aliases and stuff like that, but not require any files on hostB. The closest I've been able to come is: me@hostA> ssh -t user@hostB bash --login -c "somecommand" This connects to hostB, does the standard login stuff, runs the command, and bash exits. If it would do all that but leave bash running, I'd be happy. I think I can make it work by putting somecommand into a file named "somescript" and doing two commands: me@hostA> scp somescript user@hostB: me@hostA> ssh -t user@hostB bash --login --rcfile somescript ... but I haven't tried that, and I'd rather find a way to do it without requiring files, if possible. Anyone have any suggestions on this? --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, 2006-09-22 at 14:02 -0400, fdr-os@corona.imap.cc wrote:
I want to be able to do something like this: me@hostA> ssh user@hostB somecommand
Where the end result is that somecommand runs and _I am still logged in to hostB_, running bash as if I had done these commands:
Try screen. 1. ssh into host 2. screen -S give_name_to_session 3. run command 4. Ctrl+A D This disconnects you from that session. You can log out, log back in, and type: screen -r name_of_session Type screen -list to list sessions Hans --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
screen is great for that, but that's not quite what I'm looking for...
maybe I phrased my original post badly...
My basic problem is that when I run:
# bash -c 'command1;command2;command3'
bash does those commands, then exits. I want bash to do those commands
and not exit, without having to put the commands into a file and use
--rcname.
On Fri, 22 Sep 2006 20:48:22 +0200, "Hans du Plooy"
On Fri, 2006-09-22 at 14:02 -0400, fdr-os@corona.imap.cc wrote:
I want to be able to do something like this: me@hostA> ssh user@hostB somecommand
Where the end result is that somecommand runs and _I am still logged in to hostB_, running bash as if I had done these commands:
Try screen.
1. ssh into host
2. screen -S give_name_to_session
3. run command
4. Ctrl+A D
This disconnects you from that session. You can log out, log back in, and type:
screen -r name_of_session
Type screen -list to list sessions
Hans
--------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
--------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sun, 2006-09-24 at 09:01 -0400, fdr-os@corona.imap.cc wrote:
screen is great for that, but that's not quite what I'm looking for... maybe I phrased my original post badly...
My basic problem is that when I run:
# bash -c 'command1;command2;command3'
bash does those commands, then exits. I want bash to do those commands and not exit, without having to put the commands into a file and use --rcname.
OK, I misunderstood. Sorry, I can't help you there. Hans --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sun, Sep 24, 2006 at 09:01:05AM -0400, fdr-os@corona.imap.cc wrote:
screen is great for that, but that's not quite what I'm looking for... maybe I phrased my original post badly...
My basic problem is that when I run:
# bash -c 'command1;command2;command3'
bash does those commands, then exits. I want bash to do those commands and not exit, without having to put the commands into a file and use --rcname.
The option `-c' is not designed for an interactive bash but for executing the string provided to that option. If there is no command left in the string the short `script' given by the string does exit as usual. As you can see from manual page, the string is like script because if you add a second string after the option -c and its string this is set as positional parameters strarting with `$0': bash -c 'echo $0; echo $@' foo bar Now knowing this you may use something like this bash -c 'echo $0; echo $@; exec -l bash' foo bar ... the option -l makes the second bash a login shell. Werner -- "Having a smoking section in a restaurant is like having a peeing section in a swimming pool." -- Edward Burr --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hans, On Sunday 24 September 2006 06:01, fdr-os@corona.imap.cc wrote:
screen is great for that, but that's not quite what I'm looking for... maybe I phrased my original post badly...
My basic problem is that when I run:
# bash -c 'command1;command2;command3'
bash does those commands, then exits. I want bash to do those commands and not exit, without having to put the commands into a file and use --rcname.
Look into the "nohup" and "sleep" commands along with the shell's parentheses and process detaching ('&') operator and looping constructs. You should be able to concoct something that does what you want. However, I don't know what the virtue of keeping the shell running after all the commands it initiated are complete. Or is the goal just to hold open the descriptor, and hence the SSH connection, back to the machine that initiated the command? Randall Schulz --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
I think the 'keep bash running' was also poor phrasing on my part; I
really meant to have the bash that ran with some commands remain the
single, main logon shell for the ssh session. My original goal was to
be able to run:
# ssh user@otherhost 'some command'
and end up in bash on otherhost as user, with aliases set and
environment variables set, without having to copy over an rc file.
It looks like this is not possible; I can get ssh to run stuff before
bash, but I can't get bash to set the aliases AND keep running. The
rcfile seems to be the only way to get bash to do something as it starts
up. I think the best I'll be able to do is something like:
# ssh -t user@otherhost 'scp mainhost:specialrcfile .; bash --login
--rcfile specialrcfile'
.. but I haven't tried that yet.
Thanks to all for your ongoing comments and suggestions.
On Mon, 25 Sep 2006 05:48:49 -0700, "Randall R Schulz"
Hans,
On Sunday 24 September 2006 06:01, fdr-os@corona.imap.cc wrote:
screen is great for that, but that's not quite what I'm looking for... maybe I phrased my original post badly...
My basic problem is that when I run:
# bash -c 'command1;command2;command3'
bash does those commands, then exits. I want bash to do those commands and not exit, without having to put the commands into a file and use --rcname.
Look into the "nohup" and "sleep" commands along with the shell's parentheses and process detaching ('&') operator and looping constructs. You should be able to concoct something that does what you want.
However, I don't know what the virtue of keeping the shell running after all the commands it initiated are complete. Or is the goal just to hold open the descriptor, and hence the SSH connection, back to the machine that initiated the command?
Randall Schulz --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
--------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
fdr-os@corona.imap.cc schrieb:
I think the 'keep bash running' was also poor phrasing on my part; I really meant to have the bash that ran with some commands remain the single, main logon shell for the ssh session. My original goal was to be able to run:
# ssh user@otherhost 'some command'
and end up in bash on otherhost as user, with aliases set and environment variables set, without having to copy over an rc file.
It looks like this is not possible; I can get ssh to run stuff before bash, but I can't get bash to set the aliases AND keep running. The rcfile seems to be the only way to get bash to do something as it starts up. I think the best I'll be able to do is something like:
# ssh -t user@otherhost 'scp mainhost:specialrcfile .; bash --login --rcfile specialrcfile'
.. but I haven't tried that yet.
Thanks to all for your ongoing comments and suggestions.
Hi, I don't have the right glue about bash & shells, but the last try looks like your "specialrcfile" will be run twice, wouldn't it ? JBScout --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
fdr-os@corona.imap.cc schrieb:
I think the 'keep bash running' was also poor phrasing on my part; I really meant to have the bash that ran with some commands remain the single, main logon shell for the ssh session. My original goal was to be able to run:
# ssh user@otherhost 'some command'
and end up in bash on otherhost as user, with aliases set and environment variables set, without having to copy over an rc file.
It looks like this is not possible; I can get ssh to run stuff before bash, but I can't get bash to set the aliases AND keep running. The rcfile seems to be the only way to get bash to do something as it starts up. I think the best I'll be able to do is something like:
I suggest you have a look at 'expect' Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications. And by adding Tk, you can also wrap interactive applications in X11 GUIs. Expect can make easy all sorts of tasks that are prohibitively difficult with anything else. You will find that Expect is an absolutely invaluable tool - using it, you will be able to automate tasks that you've never even thought of before - and you'll be able to do this automation quickly and easily. http://ftp.cdut.edu.cn/pub/linux/develop/Expect/expect_nist_gov.html You will find it included in the SuSE distribution. -- Regards, Graham Smith --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 22 September 2006 20:02, fdr-os@corona.imap.cc wrote:
I think I can make it work by putting somecommand into a file named "somescript" and doing two commands: me@hostA> scp somescript user@hostB: me@hostA> ssh -t user@hostB bash --login --rcfile somescript
... but I haven't tried that, and I'd rather find a way to do it without requiring files, if possible.
Anyone have any suggestions on this?
One thing that seems to work is ssh -t user@host foo\;bash by making bash the last command, you will stay logged in --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, 22 Sep 2006 you said:
I want to be able to do something like this: me@hostA> ssh user@hostB somecommand
Where the end result is that somecommand runs and _I am still logged in to hostB_, running bash as if I had done these commands:
me@hostA> ssh user@hostB user@hostB> somecommand user@hostB>
I'd (also) give 'expect' a try. #!/usr/bin/expect -- spawn ssh chtvanw@xs4all.nl expect "Password:" send "******\r" expect -re "^chtvanw:" send "whoami\r" expect -re "^.*" interact $ ./do-xs.exp spawn ssh chtvanw@xs4all.nl Password: chtvanw:/amd/home/chtvanw $ whoami chtvanw chtvanw:/amd/home/chtvanw $ See expect(1) Theo -- Theo v. Werkhoven Registered Linux user# 99872 http://counter.li.org Voorhout ICQ: 277217131 ICBM 52 13 26N , 4 29 47E. Jabber: muadib@jabber.xs4all.nl Voor GNUpg/pgp zie headers. --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, Am Freitag, 22. September 2006 20:02 schrieb fdr-os@corona.imap.cc: [...]
I want "somecommand" to set up some aliases and stuff like that, [...]
The thread had many interesting postings, but: What's wrong with putting "somecommand" into your ~/.bashrc? Do I think too simple? ;-) Or did I overlook something? Regards, Christian Boltz -- Oder kannst du dir ein AUto vorstellen das erst mit einem Benzinmotor fabriziert wird und dann wenn du es mit Diesel betankst auch noch fährt. *lach* [Thomas Templin in suse-linux] --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (9)
-
Anders Johansson
-
Christian Boltz
-
Dr. Werner Fink
-
fdr-os@corona.imap.cc
-
Graham Smith
-
Hans du Plooy
-
Randall R Schulz
-
T. Lodewick
-
Theo v. Werkhoven