Initial setup (paths are assuming an Android target but you can obviously modify it)
cat << EOF > /data/local/tmp/shell1.sh
echo echo START >> /data/local/tmp/shell/infile
tail -n 1 -f /data/local/tmp/shell/infile | sh -i >> /data/local/tmp/shell/outfile 2>>/data/local/tmp/shell/outfile
EOF
chmod +x /data/local/tmp/shell1.sh
mkdir /data/local/tmp/shell