running commands from outside of bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting running commands from outside of bash
# 1  
Old 09-28-2004
running commands from outside of bash

Hello all!

I have two consoles.I know the PID of these two.Now I want to execute a command in console#1 but from console#2. How can I achieve this?
Anyone can do something for my query?

Click here if you can't understand my query or to know the need for this query.

Last edited by rakabarp; 09-28-2004 at 12:36 PM..
# 2  
Old 09-28-2004
Have you looked into using screen for this?

man screen

on console #1, type screen, load an app, whichever you want. Then press Ctrl-A and hit the d key.
this will detach you from the screen, placing you back on the console.

type screen -list, to see the detached screens. you can have many, note the number.
type screen -R <screen number> to reattach.

can name the screens, send commands, and more.

Now, once the screen is detached, you can ssh into the the box running console 1 (with screen), from console 2, and load that screen onto console 2. Picking right up where you left off at.

Last edited by locustfurnace; 09-28-2004 at 03:32 PM..
# 3  
Old 09-29-2004
Excellent!!!!!!!

Thanks a lot LOCUSTFURNACE!
I didn't know this 'screen' before.

I daresay this will keep me busy for some days..
I am still working with the man page of this screen command.But the
problem couldn't be solved by me yet.
The thing is I want to prepare a shell script which will first login to
another system and execute some commands in that system.All by
the script itself.Another thing is when I execute
"screen -S session_name ssh somebody@dexter" screen creates a
session called "session_name" and executes 'ssh somebody@dexter'
command so I am asked to give the password of user "somebody" at a
machine called "dexter".After supplying the password again a bash is
forked by this ssh command from "session_name"bash created by Screen.
And I do " ^C-Ad " to detach this "session_name". Then I execute
"screen -S sessin_name -X pwd". But when I reattached that session and
looked there ,that pwd hasn't been executed there.(man page says that for
password protected sessions -X option won't work.)


I think my command is being executed in
"session_name" bash and not in the bash created by "ssh" command or
something like that.

I tried "screen {ssh somebody@dexter;pwd}" thinking that both will be
executed in the new window that is going to be created by screen.Stupid
thing..It's a syntax error,I suppose. Is there any way to give two
commands on the command line?.

Even in that case also pwd will be executed in the bash created by
screen and not in the bash created by the previous command "ssh".I
couldn't comfortably tackle this problem.I AM COMPLETELY AT SEA.
# 4  
Old 03-13-2008
Hi, did you solve the problem?

Thanks

Marco
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

Running commands in backgroud

I have a small question may be this will be discussed before I have two files file1 and file2 with huge data and I am running the commands as cat file1 |sort & cat file2 |sort & If the session is got disconnected or logout will this command run in background, or shall we use nohup (3 Replies)
Discussion started by: morbid_angel
3 Replies

3. Shell Programming and Scripting

Running BASH commands from a variable

I am trying to assign a command to a variable and use it. I have tried every possible quoting variation except the correct one. :confused: Here is an example: CMD="grep description $i | grep "::"" $CMD | nawk ...Thanks in advance for you help. (1 Reply)
Discussion started by: aschera
1 Replies

4. Shell Programming and Scripting

Running sed commands

Hello I need to run some sed commands but it involves "/" in the substitute or delete, any ideas how I get round the problem. Example: cat file1.txt | sed -e '/</Header>/d' > file2.txt This errors due to the forward slash before the Header text. Thanks (3 Replies)
Discussion started by: Dolph
3 Replies

5. UNIX for Dummies Questions & Answers

Running two commands in one line

hi! how do i run 2 command from the same line e.g: 'which screen' and then ls -la 'which screen' (4 Replies)
Discussion started by: rdns
4 Replies

6. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

7. Programming

Running shell commands from C/C++

Hi guys, I know using system() we can run unix commands but the problem is, I can't get any returns with the system(). I am returning stuff from my shell scripts that I need to be able to read from my C code. Anybody has cure to this problem? :)) Thanks (2 Replies)
Discussion started by: alirezan
2 Replies

8. Programming

Running UNIX Commands from C

Hi, -How can I get number of files, cpu usage (percentage), memory usage, disk usage, ...etc, using C program ... I can use unix command ( system(command) )but I want the value to be returned back to my C program to use it in my code? How can I do that? Thanks in advance ... (2 Replies)
Discussion started by: zainab
2 Replies

9. UNIX for Advanced & Expert Users

Problem in running bash shell commands on HP-UX machine

Hello All, After login to the server we are explicitly calling /usr/local/bin/bash to activate bash shell properly. But since commands are not executing properly so I think it is not initialized well. I am facing following problems: 1) If I want to have a look on a particular file using tail... (6 Replies)
Discussion started by: abhishek0071
6 Replies

10. Shell Programming and Scripting

running commands from script

I'm new to unix and I have a fairly simple problem: Lets say I am in a specific directory and I run the command: "dirs" , I get an output of all the folders that i pushed into the stack (as expected), buut, when when I create a script (called test): #! /bin/csh dirs and then i run:... (2 Replies)
Discussion started by: owijust
2 Replies
Login or Register to Ask a Question