Linked Questions

17
votes
2answers
3k views

Why does exporting a variable in an ssh shell print the list of exported variables?

Consider this: $ ssh localhost bash -c 'export foo=bar' terdon@localhost's password: declare -x DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" declare -x HOME="/home/terdon" declare -x ...
8
votes
6answers
3k views

sh recursive copy (cp -r) - How to exclude subfolder

I need to run a remote script using ssh via Ruby (net/ssh) to recursively copy a folder and exclude a subfolder. I am looking for the fastest way to do it so rsync is not good. Also, I understand that ...
7
votes
3answers
17k views

pass variable in ssh

I'm trying to pass a variable to ssh remote but not works. My code is: #!/bin/bash set -x conexion="user@xx.yy.zz.pp" parameter="$1" ssh -T $conexion <<'ENDSSH' clear echo "$parameter" ENDSSH ...
8
votes
5answers
4k views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename "$SHELL")...
0
votes
4answers
5k views

get output of this command from another server via ssh

I'm trying to ssh into a server and get the system uptime using a specific command but it's failing to execute. this would work locally on almost all unix systems startuptime=`uptime | awk '{print $...
1
vote
3answers
2k views

How to pass the second argument in the bash function

Let's say that I have this bash function where I firstly connect to a Remote Desktop and then I want to use a second argument while I am connected to the command line of the Remote Desktop (that's why ...
5
votes
2answers
562 views

How to re-write this function to avoid argument injection

I have a function in my .bashrc file that allows me to run a script on a remote server with arguments via ssh. Currently, the function contains: function runMyScript { if [ $1 = "s3" ] then ...
3
votes
1answer
1k views

Problem with passing path containing spaces and brackets

I use Thunar file explorer and pass pathname and filename to a script audioplay. audioplay runs play command on my android via ssh which plays a song. audioplay script :: cat audioplay if [ $# -eq ...
3
votes
2answers
584 views

How to interpret ' character in a string passed through SSH

New to BASH and Linux and need some quick help. I have written a quick bash script that asks the user for a username and password from the command line and passes that info to a remote server later ...
7
votes
3answers
178 views

'switch' based on shell

I would like to source (i.e. not call) a script from any shell (bash/csh are the primary targets, but fish, zsh, ksh, and rc would also be interesting). I would like if the script can be a single ...
2
votes
1answer
396 views

BASH subprocess using SSH in script?

I want to do something like the following in a script $ ssh host1 "$(command)" However, the sub processes gets executed before the SSH connection is established because if I do the following $ ssh ...
3
votes
1answer
347 views

Executing `sh -c` script through SSH (passing arguments safely and sanely)

I suddenly realized I don't know how to execute things over SSH. I tried to do $ ssh user@server sh -c 'echo "hello"' but it outputs nothing, or rather, it outputs an empty line. If the command ...