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

All Questions

Tagged with
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
1 vote
2 answers
4k views

How to use single quotes inside ssh and sqlplus

Below script helps me to ssh and do sqlplus to fetch info from database. I checked and it worked well but the only problem is if i use single quotes in the sql query then I am getting an error since I ...
JAMUNARANI S's user avatar
1 vote
1 answer
2k views

Run for loop via ssh

Good day All, I'm attempting to run a for loop via SSH. The loop is used to get the last login of each user that has an account on the server, ssh 172.20.2.1 '''for i in `cat /etc/passwd | awk -F: '{...
jasmaar's user avatar
  • 305
2 votes
2 answers
1k views

Exported variables inside ssh session are empty

I am trying to export a variable inside a ssh session and reference the variable in the next write command. sshpass -p "password" ssh -t -t my-box <<EOF export newUrl="this is a url" sudo -...
user avatar
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
0 votes
1 answer
911 views

ssh pass multiple values

I want to open some ports i do for i in centos7{3..4};do ssh -T $i "for ir in 53 80 443 3000 3306 5910-5930 5432 8140 8443 10090-10100 20 21;do firewall-cmd --permanent --zone=public --add-port=$ir/...
elbarna's user avatar
  • 12.8k
3 votes
2 answers
3k views

ssh me@remote "<script with a for loop and variables>" - problem with variable expansion in for loop in remote script

Note - I posted a similar question yesterday and got a bit further thanks to @cas but am still having problems. I've refined the question so have re-asked it. I'm passing script text to an ssh ...
Max's user avatar
  • 61
3 votes
2 answers
6k views

Passing script string to ssh from within a bash script function - variable evaluation problem

I'm trying to write a bash script that runs a remote script via ssh as below: #!/bin/bash logfilepattern="*drupal*.gz php*.gz error*.gz" function getlogcounts { echo "in getlogcounts" echo $...
Max's user avatar
  • 61
0 votes
2 answers
2k views

how to run multiple commands with awk via ssh?

I am having difficulty on the command below. Something is not right with the awk command. I tried putting backslash but still no good. Anyone can pin point where is my syntax gone wrong? for i in $(...
Eddy.Ng's user avatar
0 votes
1 answer
93 views

Why the number is rounded over ssh? [duplicate]

localhost:~ $ df -k / | awk '{print $3/1024/1024/1024}' 0 0.00618061 localhost:~ $ ssh localhost "df -k / | awk '{print $3/1024/1024/1024}'" 01 01
phar1no's user avatar
  • 31
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
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
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
1 vote
1 answer
1k views

ssh not showing full output of command

I have a list of servers 20+ that I would like to get the shell that they are using. While logged onto a server I can run the following command $ ps -p $$ PID TTY TIME CMD 12022 pts/6 00:...
SpruceTips'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

15 30 50 per page