UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2008-11-21 01:10 PM

reachtohari@yahoo.com
Guest

Re: ssh+run process in background in script

Hi,

I am porting some test codes from Fedora core 2 to Fedora core 8.it works fine in FC2(2.6.5-1.358) but problem in FC8(2.6.23.1-42.fc8).

Pgm.c
---------
#include<stdio.h>
int main void(int)
{
fprintf(stderr,"hello world\n",);
}

$ gcc -o Pgm Pgm.c

$ vim myscript.sh
./Pgm &

$ /usr/bin/ssh -x -n -o BatchMode=yes 127.0.0.1 cd /home/tom/Test_Dir/ '&&' ./myscript.sh

If i run this command hello world is not printed.
If i run this same in FC2 hello world in printed.

Whether there is solution to this or it is a bug of FC8?

--------------------------------------------------------------------------------------------------
Below solutions are correct?.
--------------------------------------------------------------------------------------------

Solution 1:
----------
vim myscript.sh
./Pgm </dev/null >&/dev/null &

$ /usr/bin/ssh -x -n -o BatchMode=yes 127.0.0.1 cd /home/tom/Test_Dir/ '&&' ./myscript.sh 2 > log.txt

If i use this there will be no message collected in log.txt.
the messages will be discarded by using </dev/null >&/dev/null .i.e /dev/null.

I want a solution  plzz

Regards,
Hari Krishna

#2 2008-11-21 02:39 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,833
Website

Re: ssh+run process in background in script

Why the hell do you want to do such a bizarre thing??  You're running a program in
the background, which prints things to stderr (which is generally something you don't
want background processes doing!), and then trying to capture this background app's
output by running it via ssh?  Why??  I assume that's not your real app, and there's
something else you're really doing that makes some kind of actual sense, because
this makes absolutely NONE...

But, what is likely happening is that since you are running the app in the background,
the parent shell that started it is going away (and with it the ssh connection) before
the backgrounded app has a chance to ever display anything...  Add a sleep or wait
to your shell script after starting the app, before your script exits...  Or, better yet, just
run it in the foreground instead of backgrounding it!

The reason why it might work on one system but not another is due purely to luck...
Perhaps the scheduler on the old system let the backgrounded child run first, so it
managed to finish its output and exit before the parent shell ever regained control
and exited...  But, that's just purely a quirk of timing, and not something you can ever
rely on...  The bug is in YOUR code, not the system...

Offline

Board footer

Powered by FluxBB