#!/bin/bash
params=$(cat /var/tmp/patterns.txt)
remoteLog="/home/remotefile.txt"
nodes=("192.168.1.2" "192.168.1.3")
for node in "${nodes[@]}";do
ssh ${node} << 'EOF'
grep -i "${params}" "$remotelog" >/var/tmp/output.txt
EOF
done
cat /var/tmp/patterns.txt
abc
efg
ijk
I am trying to login to a remote server and grep for strings that are specified in the patterns.txt file which resides on my local machine. When I run the script, it logins to the remote machine but doesn't grep on the patterns specified in my patterns.txt file which resides on my local machine.
The script works fine if I create the patterns.txt file on the remote server but it doesn't when that file resides on my local machine from where I am running the script.
/var/tmp
is bad practice from a security standpoint as attackers can booby-trap them by creating symlinks by the same name to some files you have write access to which will end up overwritten if write something to them. – Stéphane Chazelas Jan 30 '23 at 19:38