I read a lot though the forums and Google however I wasn't able to locate a workaround for this particular one.
Basically my script is running on my local machine, then is SSH-ing onto a server with a different username (it works up until here), and on that machine I need to run some commands (they don't run).
The following is the part of the code that doesn't work:
if [[ "${TYPE}" == "cPanel" ]]; then
#Connect to the server with credentials defined earlier in the script - works properly.
ssh $USER@$HOST -p $PORT
#Get the domain by the username - works properly
user=$(sudo grep ${DOM} /etc/userdomains)
#Extract only the username from the above string - works properly
userNew=$(echo ${user} | awk 'END {print $NF}')
#Log in as the new username - works properly
sudo su -s /bin/bash ${userNew}
fi
It's a cPanel server where I need to log in as one of the cPanel users.
Help please.
P.S. The above script runs properly when ran onto the cPanel server itself. It doesn't work only when called into the SSH script on my local machine.
If you want to run the command on the remote server, then you need to put them on the end of the SSH command. Your script at the moment is using SSH to connect to the remote server but then just giving you an interactive shell on there.
You need something like this: