Allocating pty in a shell script

When a command requires a tty although it should not (some OpenStack client subcommands do), it will fail when included in a crontab. Unfortunately there is no packaged utility such as ptyget to allocate a pty. Fortunately ssh -tt can be used instead:

-t‘ Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

$ ssh-keygen
$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys
$ ssh -tt $USER@127.0.0.1 tty < /dev/null
/dev/pts/14
$ ssh -t $USER@127.0.0.1 tty < /dev/null
Pseudo-terminal will not be allocated because stdin is not a terminal.