I have a bash script that will execute a script of my choosing against a server over ssh. My problem is that I also want to use an input file with common variables so I don't have to change them in each script. So far my attempts at getting it to source the two files have resulted in it trying to find one of them on the remote machine.
input
JBLGSMR002,IP.IP.IP.IP,root,pers,pers
sourcelist
#!/bin/bash
var1="Some stuff"
var2="Some stuff 2"
Script
#!/bin/bash
#
#set -x
input="/home/jbutryn/Documents/scripts/shell/input/nodelist.csv"
sourcelist="/home/jbutryn/Documents/scripts/shell/Tools/slist"
tools="/home/jbutryn/Documents/scripts/shell/Tools"
#
is.there () {
if grep -wF $1 $2 > /dev/null 2>&1 ; then
echo "true"
else
echo "false"
fi
}
#
nodethere=$(is.there $1 $input)
#
if [[ $nodethere = "true" ]]; then
ipconn=$(awk -F ',' '/'"$1"'/ {print $2}' $input)
usrconn=$(awk -F ',' '/'"$1"'/ {print $3}' $input)
elif [[ $nodethere = "false" ]]; then
echo "Couldn't find $1 in database"
exit 1
fi
#
if [[ -f $tools/$2 ]]; then
echo "Please enter your password for $1: "
read -s SSHPASS
eval "export SSHPASS='""$SSHPASS""'"
sshpass -e ssh $usrconn@$ipconn < "$tools/$2"
elif [[ ! -f $tools/$2 ]]; then
echo "Couldn't find $2 script in the Tools"
exit 1
fi
I have this test script to see if it's passing the variables to the remote machine:
Test Script
#!/bin/bash
#
touch testlog
echo $var1 >> ./testlog
echo $var2 >> ./testlog
And this is what I've tried so far to get the sourcelist to pass through:
if [[ -f $tools/$2 ]]; then
echo "Please enter your password for $1: "
read -s SSHPASS
eval "export SSHPASS='""$SSHPASS""'"
sshpass -e ssh $usrconn@$ipconn < "$sourcelist"; "$tools/$2"
This one will create a blank testlog file on the local machine
if [[ -f $tools/$2 ]]; then
echo "Please enter your password for $1: "
read -s SSHPASS
eval "export SSHPASS='""$SSHPASS""'"
sshpass -e ssh $usrconn@$ipconn <'EOF'
source $sourcelist
bash "$tools/$2"
logout
EOF
This one will create a blank "testlog" file on the local machine
I've also tried using source bash . to call the files but I still can't seem to get both local files to pass to the remote machine. Anyone know how this can be done?