I have a bash script test.sh that contains the following commands
#!/bin/bash
PASSWORD=""
USERNAME=""
REM_HOSTNAME='localhost'
FILES_TO_COPY="remote_exec.sh"
function scptmp {
exec sshpass -p $PASSWORD scp -o "ConnectTimeout 3" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
"$@"
}
echo -e "\tCopying files to remote host..."
scptmp -r -q $FILES_TO_COPY $USERNAME@$REM_HOSTNAME:/tmp
echo -e "\tSet execution privs on remote file..."
sshpass -p "$PASSWORD" ssh -t -oStrictHostKeyChecking=no $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S chmod +x /tmp/$FILES_TO_COPY"
echo -e "\Execute..."
sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -t $USERNAME@$REM_HOSTNAME "echo $PASSWORD | sudo -S bash /tmp/$FILES_TO_COPY"
And the remote_exec.sh with the following content:
#!/bin/bash
hostname=`hostname`
mkdir $hostname
When I execute the script with
bash test.sh
I don't receive any error, but the remote_exec.sh doesn't seem to be executed on the host since no directory is created.
Does anyone have an idea what the problem might be?
set -xbefore running the script? Do you have the shebang on the first line of your script?test.sh?set -xnow in the terminal before executingbash test.shbut it just returns+ bash linux_pentest.shsshpass.