sudo: no tty present and no askpass program specified

Posted on 2011-04-22
Last Modified: 2013-12-16
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/*

# 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;
    echo "ORACLE SID: " $sid
    export ORACLE_SID=$sid
    . ~/${ORACLE_SID}.env > /dev/null

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


# Transfer compressed PAI data to FTP server.
sudo -u ch33data /home/ch33data/bin/ >> ${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

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

Open in new window

Question by:Michael W
    LVL 31

    Assisted Solution

    Unfortunately, there are still problems with your sudo file, you need to use NOPASSWD option since script cannot enter password and the second thing is that sudo is very literal.  It would not accept globbing.  You  need to enter the entire commands.

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

    You need to use
    oracle        ALL=(ch33data)       NOPASSWD: /home/ch33data/bin/scriptname
    LVL 29

    Accepted Solution

    Actually, the following became the solution after I did a bit more research:

    ## External PAI Server
    Runas_Alias PAI = ch33data
    #Defaults    requiretty
    oracle          ALL = (PAI) NOPASSWD: /bin/sh, /bin/*, /home/ch33data/bin/*

    Open in new window

    LVL 29

    Author Closing Comment

    by:Michael W
    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:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
    You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now