1

I am using STAF to automate db2 interface testing with our product. I am able to run the command using su - db2inst1 -c "/home/db2inst1/sqllib/bin/db2 list database directory" but when I try the same command with the staf interface I am getting the error:

standard in must be a tty

I commented the "Defaults requiretty" in /etc/sudoers, but still have the same issue.

Caleb
  • 11,813
  • 4
  • 36
  • 49
Sanjeev
  • 11
  • 1
  • 1
  • 2
  • How were you connecting or logging in to the terminal? Using ssh ? Using docker exec ? Other ? A pty is not being allocated. Use 'ssh -t' or 'ssh -tt' to control allocation of pty when logging in with ssh. That and two other answers on how to solve or work around missing tty here: http://stackoverflow.com/questions/36944634/su-command-in-docker-returns-must-be-run-from-terminal/41872292#41872292 – gaoithe Jan 26 '17 at 11:25

3 Answers3

2

Drop the lone dash (-) in your su command. That triggers su to ask for a login shell. A tty might be required by some program in your login chain.

Caleb
  • 11,813
  • 4
  • 36
  • 49
  • 1
    If you remove the dash, you'll need to make sure to set the DB2-related environment variables for that command. – justarobert Apr 15 '11 at 11:54
0

/etc/sudoers does not govern the behavior of su. You want something like

sudo -u db2inst1 "/home/db2inst1/sqllib/bin/db2 list database directory"
justarobert
  • 1,869
  • 13
  • 8
  • Actually sudo doesnot work with STAF framework, so I need to execute it with su - useranem -c Command only. – Sanjeev Apr 15 '11 at 10:07
  • `su` doesn't normally have the restriction of needing to run in a tty; it's used all the time in init scripts, for example. Could this be a limitation of the db2 binary or of staf? What happens when you put the command into a shell script and run it? – justarobert Apr 15 '11 at 10:17
0

Please refer this link: I tried the 2nd option of ssh -t username@server 'sudo command'. It worked for me. https://math-linux.com/linux/bash/article/error-standard-in-must-be-a-tty-when-doing-ssh-username-server-sudo-command