Can I use GNU make's SHELL variable to connect to a remote shell? - testing

One of the projects I'm working on uses gnu make for testing. I would like to test on a platform that doesn't have a make implementation, but does have a POSIX shell.
Is it possible to create a script (preferably in python) that can "stitch" a remote shell to make, and put it in make's SHELL environment variable?
If not, is there another way anyone can think of to do it?

It is possible.
Create a script that forwards commands to a remote host. For example:
#!/bin/bash
shift # remove -c argument
exec ssh remote_host "$#"
And make it executable (chmod +x).
And then in Makefile:
SHELL := './my_shell.sh'
all :
#echo `hostname` is making $#
Outputs:
$ make
remote_host.peer1.net is making all

Related

Where to set environment variables for non interactive bash use?

If I add an export declaration in ~/.bashrc the environment variable is available only if I use bash interactively, not when I invoke a command as argument to bash, e.g. bash -c export.
Where do I set environment variables so that they are available both in interactive and non-interactive mode?

Command works in shell but not Objective-C or C

I want to run the following shell command in Objective-C
sshfs -C -p 22 user#remote.computer.com ~/local/directory/path
using the command system("sshfs -C -p 22 user#remote.computer.com ~/local/directory/path");
but I get sh: sshfs: command not found in NSLog.
If I copy and paste it into terminal however, it works.
The path used by an GUI application does not include any changes you have made in your shell files in your home directory (e.g. ~/.bashrc)
One way is to use the full path in the system call. (i.e. /Users/username/Projects - ~ are not automatically expanded) In a Cocoa app I would use NSTask to give more control

How to make shell script run by double-click?

I have a script which is executable from command line but I want to make it user friendly as I want to run this script by double clicking on it. How it is possible?
#! /bin/bash
cd
cd Desktop/D_usman/
java -jar imageSynch.jar
You may need to add ".command" to the end of the name of your shellscript on Mac OS X.
You need to add execute permissions for the user, group, or rest of the world, depending on who should be allowed to execute it. Look into chmod for more information.
Example: chmod u+x myscript
Once you do this, you can also start the shell script like this ./myscript instead of sh myscript.sh
Note: You can also make your JAR start by adding execute permission, given Java is setup correctly on your machine.

How can i set a local variable in ssh?

I would like to set a local variable in a ssh command-chain that is only used in this environment:
#!/bin/sh
my_var='/tmp/wrong_file'
ssh user#server "my_var='/tmp/a_file'; cat $my_var;my_var=123;echo $my_var"
echo $my_var
This example the "outer" $my_var is used. How to fix this and use variables "in" the current ssh connection as locally defined? There is no need to change or access the external value '/tmp/wrong_file' in $my_var, as asked in Assign directory listing to variable in bash script over ssh.
You're using the wrong quotes. Parameter expansion is performed inside double quotes, but not inside single quotes.
#!/bin/sh
my_var=/tmp/wrong_file
ssh user#server 'my_var=/tmp/a_file; cat $my_var;my_var=123;echo $my_var'
First of all: The SSH shell and your local shell are completely different and do not exchange any environment variables. This is a good thing - consider environment variables such as LD_LIBRARY_PATH when using SSH between machines of different OS architecture.
IMHO the best solution for your problem is to encapsulate your commands into a shell script on the remote side, then maybe start it with parameters. E.g.:
Remote:
myscript.sh contains:
#!/bin/sh
MY_FILE="$1";
echo "Contents of §MY_FILE:"
cat $MY_FILE
Local:
RUn something like
export REMOTE_FILE='/path/to/it'
ssh user#server "/path/to/myscript.sh '$REMOTE_FILE'"

How to inject commands at the start of an interactive SSH session?

I want to be able to just ssh to a server where I cannot modify profiles and set up the environment with several commands before getting the usual interactive session.
Any ideas?
I've been using an expect script with an "interact" command at the end - which works for most things but is clumsy and breaks some console apps. Also been extermienting with empty-expect and socat. Any other suggestions?
If you're able to write somewhere on the filesystem, you may be able to invoke bash with a custom rc file like this:
ssh me#example.com -t bash --rcfile /home/user/my_private_profile -i
Note that this appears to only work for interactive shell, not login shells. The -t option to ssh makes it allocate a pty even though you're specifying a command.
If you can't write to the filesystem anywhere, you could use a subshell to supply a named pipe as the rcfile:
$ ssh ares -t "bash --rcfile <(echo 'FOO=foo';echo 'BAR=bar') -i"
axa#ares:~$ echo $FOO
foo
axa#ares:~$ echo $BAR
bar