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

All Questions

Tagged with
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
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
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
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
3 votes
1 answer
391 views

View remote value of $PATH inside shell script

When executing this bash script, it only shows my local path. ssh ${REMOTE_HOST} 'bash -s' <<EOL set -e source ~/.profile echo $PATH # Commands here don't work because $PATH is ...
Flash's user avatar
  • 133
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
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
4 votes
2 answers
13k views

How to run a remote sed command through ssh if the data includes double quotes ("")?

I'm trying to run through a list of servers and run the next command: itaig@itaig-lt:~$ ssh root@$srvname "sed -i 's/VNCSERVERARGS[6]="-geometry 1920x1080"/VNCSERVERARGS[6]="-geometry 1152x864"/g' /...
Itai Ganot's user avatar
3 votes
1 answer
561 views

Why do I get an error when double quoting single quotes in a script that launches a remote SSH command?

I have this script: port=$1 cmd=$2 ssh [email protected] -p $port "'"$cmd"'" When running myscript.sh 1000 "ls /dev/shm" it get this error: bash: ls /dev/shm: No such file or directory In the script, ...
TCZ8's user avatar
  • 1,079
3 votes
2 answers
3k views

Execute command through SSH

I am writing a script to check whether all the servers in my organization are functioning properly. One of those is Zimbra mail server. I am trying to send a mail through sendmail provided by zimbra ...
Dharmit's user avatar
  • 4,330
2 votes
2 answers
7k views

Using exec in find over ssh from shell script

So, I am attempting to execute the following from within a shell script; ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit" When this runs, it ...
Skittles's user avatar
  • 143
2 votes
1 answer
1k views

Copy newest file in directory over SSH

How might one copy the newest text file from a particular directory on a remote server to his local machine? On the server itself I can do the following: $ cat `cd /home/user/dir ; readlink -f $(ls -...
dotancohen's user avatar
  • 16.1k
2 votes
2 answers
5k views

How to escape quotes in shell within both usage of ssh and sudo?

In one word: question and example could test locally: sh -c "echo 'how to print single quote here'" details: I have a config like this: upload_server = ('192.168.1.1', 10051) now I need a shell ...
jixiang's user avatar
  • 121
0 votes
2 answers
2k views

Run ssh command without quotes

You can execute a command on a remote server using ssh user@host 'the command' but is there a way to execute the command without quotes? (I am on BSD and using OpenSSH)
Alexander Mills's user avatar