On Tue, 12 Mar 2002, Maxim Ryabenko wrote:> Hello! > > I want to detect some environment on a remote host (in C program, getenv()), > but it is failed. Here is a little program which I try to run on a remote > host with command: "#ssh myhost myecho" > > /* myecho */ > #include <stdio.h> > main (){ > char *dir; > if ((dir = getenv("MYDIR")) != NULL) > printf ("environment is %s\n",dir); > else > printf ("enviroment is not specified.\n"); > } > > it returns "enviroment is not specified.", although the environment MYDIR is > specified in /etc/profile on a remote host. > In this way I can detect only $PATH, $USER, $HOSTNAME, but not MYDIR :( > > On the other hand "./ssh myhost echo $MYDIR" works correctly >First off do: ./ssh myhost echo \$MYDIR All $xx and * are resolved BEFORE commands run.. the escape ensure it is not. Second /etc/profile is not read by non-tty sessions. try: ssh -t myhost echo \$MYDIR to see if you get better results. - Ben
Hello! I want to detect some environment on a remote host (in C program, getenv()), but it is failed. Here is a little program which I try to run on a remote host with command: "#ssh myhost myecho" /* myecho */ #include <stdio.h> main (){ char *dir; if ((dir = getenv("MYDIR")) != NULL) printf ("environment is %s\n",dir); else printf ("enviroment is not specified.\n"); } it returns "enviroment is not specified.", although the environment MYDIR is specified in /etc/profile on a remote host. In this way I can detect only $PATH, $USER, $HOSTNAME, but not MYDIR :( On the other hand "./ssh myhost echo $MYDIR" works correctly What is wrong? Thank you! Maxim
> The remote /etc/profile is not executed when you run a remote command > using ssh. Your remote echo appears to do what you want because > variables get expanded inside double quotes. Try it like this: > > ssh myhost 'echo $MYDIR' > > If you want the remote profile to be executed, you have to do something > like this: > > ssh myhost '. /etc/profile; echo $MYDIR' > > Happy computing! > > Paul AllenThank you, Paul and Ben. this is what I want, ssh myhost '. /etc/profile; echo $MYDIR' It works good, thank you. Problem was not in standard command "echo". It was in my program (see prev. message). This one works ....... if ((dir = getenv("MYDIR")) != NULL) ....... But this not ....... if ((dir = getenv("PATH")) != NULL) ....... It seems that there is another place (not /etc/profile), where environments PATH etc. are stored. But where? Can I put my environment there and do not run . /etc/profile like this: ssh myhost '. /etc/profile; ............' Thank you so much! p.s. sorry, my English is worst. Maxim