Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
33 votes
4 answers
14k views

Quoting in ssh $host $FOO and ssh $host "sudo su user -c $FOO" type constructs

I often end up issuing complex commands over ssh; these commands involve piping to awk or perl one-lines, and as a result contain single quotes and $'s. I have neither been able to figure out a hard ...
Leo Alekseyev's user avatar
29 votes
2 answers
6k views

How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

ssh has an annoying feature in that when you run: ssh user@host cmd and "here's" "one arg" Instead of running that cmd with its arguments on host, it concatenates that cmd and ...
Stéphane Chazelas's user avatar
25 votes
3 answers
33k views

ssh command with quotes

I have an odd error that I have been unable to find anything on this. I wanted to change the user comment with the following command. $ sudo usermod -c "New Comment" user This will work while logged ...
SpruceTips's user avatar
17 votes
3 answers
59k views

Remote for-loop over SSH

I have the following in a script for server in ${servers[@]}; do echo ${server} ssh user@${server} "for i in /tmp/foo* ; do echo ${i}; done" done But it doesn't work. Weird thing, I see $I ...
Eldelshell's user avatar
17 votes
4 answers
27k views

bash adds extra single quotes

I have a problem executing my script. When executing it in debug mode (bash -x), I can see that bash is adding extra quotes. Therefor my script is failing. Here this is within my script: testvar="\...
user2452585's user avatar
15 votes
3 answers
4k views

How do ssh remote command line arguments get parsed

I've seen the questions and answers about needing to double-escape the arguments to remote ssh commands. My question is: Exactly where and when does the second parsing get done? If I run the ...
onlynone's user avatar
  • 636
7 votes
3 answers
676 views

How would you gracefully handle this snippet to allow for spaces in directories?

I have a series of commands, e.g.: ssh -i key 10.10.10.10 mkdir -p "${DEST_PATH}/subdir1" "${DEST_PATH}/subdir2" rsync "${SOURCE_PATH}" "$DEST_HOST:${DEST_PATH}/...
JoeSlav's user avatar
  • 128
6 votes
3 answers
4k views

Passing multiple of arguments with whitespaces through a script to ssh

I want to remove multiple files from remote server. I have all files under one array in a script and I call other script which will remove files. Let output of "${b[@]}" is: /mnt/DataBK/...
AVJ's user avatar
  • 505
5 votes
2 answers
18k views

About escape with SSH pipe

I want to execute the awk command with long parameters,like this: ssh host "netstat -rn|awk 'NR!=1 && NF>=6 && $1!="Destination" {printf "%-15s %-20s\n", $1, $2}'|sort -f " but ...
CatWin's user avatar
  • 51
5 votes
2 answers
14k views

Passing a list of two PIDs to xargs only kills the first using ssh

I'm retrieving a list of two PIDs that I want to kill. My pipeline looks something like ps -ef | grep foo | grep -v grep | awk {'print $2'} | xargs kill -9 Both processes are killed when executing ...
Steve's user avatar
  • 213
5 votes
3 answers
26k views

Kill remote process via ssh

I have a process that I want to kill remotely. I tried ssh remotehost "kill -9 $(ps -aux | grep foo | grep bar | awk '{print $2}')" but this returns the error kill: usage: kill [-s sigspec | -n ...
chrise's user avatar
  • 231
5 votes
2 answers
2k 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 ...
cpd's user avatar
  • 153
4 votes
3 answers
7k views

awk in ssh command line complains 'unexpected newline or end of string' How to resolve?

While running the below script had an issue, ^ unexpected newline or end of string How could I resolve this ? [root@emrbldbgdapd2 ~]# ./collectdata.sh collect the data of 10.209.61.124 awk: cmd. ...
Levyle's user avatar
  • 41
4 votes
1 answer
1k views

Using a function's output (defined locally) inside SSH call

I have created a function function getqueue() { urlqueuename="urlcall" ouput=`curl $urlqueuename` queue=$(echo $ouput | jq -r '.queueName') echo $queue } I am using a ssh call ...
Ajith Sasidharan's user avatar
4 votes
2 answers
6k views

Is it possible to escape quotes within escape quotes within escape quotes within escape quotes?

I'm trying to do is run a command inside an... su - someuser -c "ssh someplace \"if ( ! grep <b>[WHAT DO I PUT HERE?]</b>some thing<b>[WHAT DO I PUT HERE]</b> /etc/somefile ); ...
Peter Turner's user avatar
  • 1,694

15 30 50 per page
1
2 3 4 5 6