A better/easier way than using expect is SSHPASS, which sends a password through with an SSH request:
sshpass -p <PASSWORD> ssh <USER>@<SERVER> <SSH Command>
PASSWORD is the password to be entered when prompted, USER is the username, SERVER is the server IP Address (eg. 10.8.100.100) and SSH Command is the command you want to execute.
For your example:
sshpass -p <PASSWORD> ssh [email protected] mkdir <full path for new dir>
To install SSHPASS:
sudo apt-get install sshpass
If you are wanting the SSH session to remain afterwards than you can use expect with the following,
#!/bin/bash
##Enter Username and Password Details:
userName=<UserName>
password=<Password>
expect -c "
spawn ssh ${userName}@10.8.100.100 ##put your own IP here
expect "password: " ##or whatever password prompt you get
send "$password\r"
expect -re "Last Login: " ##or whatever the end of your welcome message is
send "su -i"
expect "password for <UserName>"
send "$password\r"
"
This will leave the root access logged in, however until the script sends a return statement it will hold control until you hit Ctrl+c. But this should answer your question.