Link to home
Start Free TrialLog in
Avatar of Michael Worsham
Michael WorshamFlag for United States of America

asked on

sudo: no tty present and no askpass program specified

I'm stuck. Our Oracle DBA has a script (see code below) which triggers a transport script (from another user's account) to transfer the file over to an external server using the local ch33data userid. However, the message that keeps appearing if the script is run via cron:

sudo: no tty present and no askpass program specified

In the /etc/sudoers file, I have commented out the "Default requiretty" and added the following for the oracle userid:

# Allow user oracle to run commands specified
oracle          ALL=(ch33data) /bin/sh, /bin/*, /home/ch33data/bin/*

#!/bin/sh
# Execute the Materialized Views Refresh, Export, Zip, and Transfer scripts.

set -x
. ~/.bash_profile > /dev/null

### Setting ORACLE_SID
dblist=`cat /etc/oratab | grep -v "#" | awk -F: '{ print $1 }'`
for sid in $dblist;
  do
    echo "ORACLE SID: " $sid
    export ORACLE_SID=$sid
    . ~/${ORACLE_SID}.env > /dev/null
  done

dtStamp=`date +%m%d%y`
# LOG_DIR= --set in profile
EXEC_LOG=${LOG_DIR}/ch33_mview.${dtStamp}.exec.${ORACLE_SID}.log
exec > ${EXEC_LOG} 2>&1

echo "ORACLE_SID is " $ORACLE_SID > ${EXEC_LOG}

# Transfer compressed PAI data to FTP server.
sudo -u ch33data /home/ch33data/bin/pai_exp_mview_transfer.sh >> ${EXEC_LOG}

# Report success or failure for file transference
if [ ${STATUS} -ne 0 ]; then
  echo "subject:FAILED PAI File Transfer."  | cat - $SCRIPT_DIR/emailDist/testHeader.txt ${EXEC_LOG} | /usr/sbin/sendmail -t
  exit 1
fi

echo "subject:SUCCEEDED $ORACLE_SID PAI Transfer."  | cat - $SCRIPT_DIR/emailDist/testHeader.txt ${EXEC_LOG} | /usr/sbin/sendmail -t

Open in new window

SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael Worsham

ASKER

First I tried the following:

oracle          ALL = (ch33data) NOPASSWD: /bin/sh, /bin/*, /home/ch33data/bin/*

But ‘visudoers’ command had a hissy fit over it (i.e. would not allow the file to save as it found a syntax error).

I found that the Runas_Alias was what was needed, then the visudoers command allowed the variables to be saved.

Reference site: http://www.gratisoft.us/sudo/sudoers.man.html