All Questions
76
questions
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}/...
1
vote
1
answer
709
views
RemoteCommand with percent signs doesn't work
The following command
tmux new -A -s $(date +%Y%m%d%H%M%S)
works and starts tmux with a session, named after current datetime (as expected).
But if I put the same in ssh config
RemoteCommand tmux new ...
0
votes
1
answer
7k
views
I received error "bash: line 1: [: -ne: unary operator expected" after run the below script
This script provides the expected output, but throw the error "bash: line 1: [: -ne: unary operator expected". Techies help to fix this.
#!/bin/bash
USR="root"
# Email
SUBJECT="NTP Service Status ...
0
votes
1
answer
661
views
how to use quotes in sed & ssh?
i cant get this to work in bash/rhel 7:
ssh host "sed -i -e \"s/dnl MASQUERADE_AS.*\$/MASQUERADE_AS(\`domain.com\')dnl/\" /etc/mail/sendmail.mc"
bash: -c: line 0: unexpected EOF while looking for ...
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)
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 ...
1
vote
3
answers
603
views
SSH with Command Doesn't Run as an Alias
I have the following command to remote into a local server and tail -f the latest log file for an application that I have.
The command works perfectly fine from the command line -
ssh user@hostname ...
2
votes
3
answers
6k
views
Bash Script to remotely collect hostname, IP and host total memory
I am trying to write a scrip that will collect the hostname, IP and total memory installed on remote hosts from a list I feed into the script. The script will collect information from Redhat and ...
2
votes
4
answers
34k
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 $...
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
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. ...
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 ...
0
votes
1
answer
214
views
Having trouble with sqlite3 ssh command (I am assuming bad quotes)
The following works great:
ssh plxch1035.pdx.xxxxxx.com "sqlite3 /p/hdk/rtl/proj_data/shdk74/fe_data/ipci/ipci.db 'select * from tools'"
When I want a specific tool row though:
ssh plxch1035.pdx....
3
votes
4
answers
6k
views
Avoid escaping of double quotes
I have some commands I want to execute in a bash script.
Now when we use single quotes the variable is taken literal and not the value.
So doing e.g. ls "$SOME_DIR" is not the same as ls '$SOME_DIR'
...
3
votes
1
answer
740
views
Nested quotes nightmare : sending an e-mail from a remote host
I need to send (from my terminal) an email with attachments from my remote host which I access by ssh.
I already know that to do something remotely, I use
ssh -p myport [email protected] "...
2
votes
1
answer
10k
views
Send variable with EOF and use host variable [duplicate]
I want to send variable from source to host, and exec host script.
Here is my code :
var1=1
ssh -p 42 root@xxx /bin/bash << EOF
var2=2
echo $var1
echo $var2
EOF
Return : 1
var1=1
ssh -...
0
votes
2
answers
2k
views
If condition not working in script over ssh
Below shell script on SSH mode is not working.
variable end_pos is getting value "Stop", but when it comes in IF loop , it doesn't check the condition and loop is getting failed.
Output of command :
...
0
votes
1
answer
205
views
ls -td fails to identify any directories
I'm having a bit of a problem working on a shell script. One of the commands within the script is used to push a set of commands from a Jenkins host to MySQL database hosts to run backups "locally" to ...
3
votes
2
answers
9k
views
How to copy files using scp from remote host when file have spaces
I need to copy a file from remote host to my local directory using scm where a file have spaces, for not I fixed the issue by ssh to that host and scp the file back. But I want to know how to copy ...
0
votes
1
answer
797
views
Date command is not working in remote server when running using a script
I am running below command from a script from a remote server, but getting error No such file or directory
ssh -t -t [email protected] \"sudo mysql nss_mysql < /home/user/scripts/Db_nss_mysql-`date ...
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
...
0
votes
1
answer
2k
views
mask Dollar, brackets and quotes in remote ssh command [duplicate]
I want to do some script on a remote mashine through ssh:
ssh Server "V=\$\(lua -e 'print\(require\(\\\"platform_info\\\"\).get_image_name\(\)\)'\); echo \$V"
But this echo $V at the end gives me ...
0
votes
3
answers
1k
views
issue with back quotes inside while loop when running a command over ssh
This question is a bit complicated. I will try to explain in detail.
I have two machines, one is local and other say 192.168.1.2. I have set the following variables in my local machine
CHECK="/home/...
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 ...
0
votes
2
answers
815
views
Environment variables over ssh block in shell script [duplicate]
I have the following function :
GetHostName () {
NODE01_CHECK=`cat /etc/hosts | grep -w "node01" | awk '{print $1}'`
NODE02_CHECK=`cat /etc/hosts | grep -w "node02" | awk '{print $1}'`
IS_NODE1=`...
2
votes
2
answers
273
views
Multiple commands with quotations after SSHing
I have a server I have to ssh into with many commands which feature the use of variable assignment and consequently a lot of quotation marks. If we consider the script:
ssh user@host "kinit -k -t /...
1
vote
4
answers
1k
views
execute command over ssh connection [duplicate]
I want to excecute the following command over a ssh connection:
tmpValue=$(cat /var/run/jboss-as/jboss-as-standalone8.pid) && top -b -U jboss -n 1 |grep $tmpValue |awk '{print $9}'
This ...
2
votes
1
answer
1k
views
Syntax error with variable containing quotes
I have a bunch of Linux machines behind 2 gateways. To connect to set one I do
ssh -o ProxyCommand="ssh gateway1 nc %h %p" machines_behind_1
ssh -o ProxyCommand="ssh gateway2 nc --proxy %h %p --...
4
votes
2
answers
3k
views
Why some commands don't load user environment when executed with ssh? (while other do)
On a target machine (OS X El Capitan) I have brew in /usr/local/bin. When I try to get brew's path I get no result:
# ssh [email protected] -p 2222 which brew
#
Troubleshooting:
brew is in /usr/...
2
votes
4
answers
760
views
Why does read with pipeline fail in an ssh session?
Why does this show blank lines instead of folders found by find?
ssh -o stricthostkeychecking=no -o userknownhostsfile=/dev/null \
-o batchmode=yes -o passwordauthentication=no [email protected] \
...
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 ...
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 ...
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: '{...
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 -...
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/...
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/...
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 ...
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 $...
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 $(...
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
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 ); ...
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 ...
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 ...
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:...
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 ...
0
votes
1
answer
380
views
Syntax Error while running command from another hosts [duplicate]
I run a command to fetch server uptime as below
[root@localhosts ~]# printf "`uname -n` `uptime| awk -F " " {'print $3,$4'}`\n"
localhosts 75 days,
Now when I run same command from another ...
0
votes
2
answers
2k
views
Exclude the output from ssh and only log the error if found
typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} "
$(cat);
IFERROR=$(checkscript);
echo "$IFERROR"" > ${SSHTEMPFILE} 2>&1
This line...I can't exclude the "...
1
vote
3
answers
2k
views
find: missing argument to `-exec'
when I'm trying to use this command
var1=`sudo -u psoadmin -H -s ssh [email protected] find . -maxdepth 1 -type f -mtime +14 -exec ls -lh \{} \; | awk '{print $5, $9}'|egrep -v '^./...
1
vote
2
answers
3k
views
ssh inside a script with 'command' instead of "command"
I am trying to run commands on various nodes of our cluster automatically via a simples script. I have seen that I can run:
#!/bin/bash
echo "Machine: "$HOSTNAME;
ssh machine2 'echo Machine: $...
1
vote
2
answers
1k
views
Any special permission ssh remote command working on fifo file(aka named pipe)?
I need to redirect some strings to a fifo file with ssh remote command, but always got permission denied, the command I executed is:
ssh rundeck@nagios1 sudo su - root -c 'printf "...