All Questions
76
questions
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 ...
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 ...
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 ...
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 ...
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="\...
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 ...
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}/...
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/...
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 ...
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 ...
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 ...
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
...
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. ...
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 ...
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 ); ...