Page 1 of 1

Cron Job failing with no TTY present

Posted: Mon May 28, 2018 2:45 pm
by pabelford
I am working on a custom backup script that will move the vesta built backups to a remote windows server. I know its a little odd but its what I have. The share "/cifs" is mounting fine and accessible. I have built the script to check to make sure the mount is active and if not then mount the drive and creates a log entry. Once mounted it copies the backup files over but only the new ones. It then removes any backups that over 7 days. This script requires Sudo. I have tested and verified that the script runs fine in SSH, but does prompt for a password. I have added it to the Cron section on admin user in VestaCP but it keeps failing with sudo: no tty present and no askpass program specified.

The Server is VestaCP built on CentOS 7.

Here is the Script located in /etc/scripts

Code: Select all

#!/bin/bash
#start
#-----------------------------------------------------------------------
dt=$(date '+%d/%m/%Y %H:%M:%S');

if [[ $(findmnt "/cifs") ]]; then
    echo $dt" Mounted" >> /var/log/cifs_mount.log
else
    echo $dt" Not mounted" >> /var/log/cifs_mount.log
    mount -a
fi

cp -u /backup/* /cifs/daily/users
find /cifs/daily/users/ -name '*.tar' -mtime +7 | xargs rm -f;
find /cifs/fullsystem/ -name '*.gz' -mtime +30 | xargs rm -f;
# Are Weekly Backups Implemented?
# find /srv/backup/weekly/ -name '*.gz' -mtime +14 | xargs rm -f;
#-----------------------------------------------------------------------
#end
Here is my sudoers.d/admin file

Code: Select all

# Created by vesta installer
Defaults env_keep="VESTA"
Defaults:admin !syslog
Defaults:admin !requiretty
Defaults:root !requiretty

admin   ALL=(ALL)       ALL
admin   ALL=NOPASSWD:/usr/local/vesta/bin/*, /etc/scripts/*
  1. I have tested from SSH, Script works fine but requires a password.
  2. I have added /etc/scripts/* to the sudoers.d/admin file. and updated the Cron Tab of VestaCP No avail.
  3. I have moved a copy to /usr/local/vesta/bin/* and added that location to the Cron Tab on VestaCP no avail. all other sudo scripts in the /usr/local/vesta/bin/* run with no issues.
  4. I have verified permissions are set to 755 and root:root like all the other scripts in /usr/local/vesta/bin/*.
  5. I have intentionally and temporary commented "Defaults:admin !requiretty" no avail.
I'm at a loss of that is forcing the requirement of password which needs tty when it is specified no password for the folders it is located and other scripts built by Vesta in the same folder sudo with no password.

Does any one have any suggestions on this issue?

Re: Cron Job failing with no TTY present

Posted: Thu May 31, 2018 5:49 pm
by pabelford
I have found the solution to my troubles. It would seems the VestaCP runs commands in the web CP without the initial "." to indicate its an executable file.

Correct command in the web VestaCP

Code: Select all

sudo /etc/scripts/backup-fullsystem.sh
How you would expect it in crontab -e or from ssh, which does not work correctly in vestacp.

Code: Select all

sudo ./etc/scripts/backup-fullsystem.sh
Funny how one little period can create a problem that takes a while to figure out.

Kudos to the VestaCP guys. This is probably the most user friendly and second only to cpanel in terms of stability of all the CPs I have used. Keep up the great work!

Re: Cron Job failing with no TTY present

Posted: Sun Apr 28, 2019 2:50 pm
by blondie101010
I'm answering in case it could be useful to someone.

The main problem reported is due to the sudoers entry which allows...

Code: Select all

/etc/scripts/*
sudoers rules are very strict for security reasons and need to be an exact match to the rule.

./etc/scripts/backup-fullsystem.sh does not match /etc/scripts/*

As a final note, VestaCP does not redefine how a Linux system works, it simply runs on it.

Re: Cron Job failing with no TTY present

Posted: Mon Aug 26, 2019 2:19 am
by plutocrat
Just in case this helps anyone. I suddenly started getting this message from a server for ALL admin cron jobs "sudo /usr/local/vesta/bin/v-update-sys-rrd" etc.

I was asleep at the time and woke up to some 500 email messages! The message was "sudo: no tty present and no askpass program specified"

So it turns out this was due to me editing the sudoers file the previous day. At the bottom of the file is a line which looks like a comment but isn't.
#includedir /etc/sudoers.d
I'd removed this line in my editing. Without that, the file /etc/sudoers.d/admin isn't processed, and that's where Vesta sets up admin permissions to run the cron jobs without a password. So basically that error message is cron complaining it needs a password.