We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Cron Job failing with no TTY present Topic is solved
Cron Job failing with no TTY present
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
Here is my sudoers.d/admin file
Does any one have any suggestions on this issue?
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
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/*
- I have tested from SSH, Script works fine but requires a password.
- I have added /etc/scripts/* to the sudoers.d/admin file. and updated the Cron Tab of VestaCP No avail.
- 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.
- I have verified permissions are set to 755 and root:root like all the other scripts in /usr/local/vesta/bin/*.
- I have intentionally and temporary commented "Defaults:admin !requiretty" no avail.
Does any one have any suggestions on this issue?
Re: Cron Job failing with no TTY present
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
How you would expect it in crontab -e or from ssh, which does not work correctly in vestacp.
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!
Correct command in the web VestaCP
Code: Select all
sudo /etc/scripts/backup-fullsystem.sh
Code: Select all
sudo ./etc/scripts/backup-fullsystem.sh
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!
-
- Posts: 1
- Joined: Sun Apr 28, 2019 1:40 pm
- Os: CentOS 6x
- Web: apache + nginx
Re: Cron Job failing with no TTY present
I'm answering in case it could be useful to someone.
The main problem reported is due to the sudoers entry which allows...
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.
The main problem reported is due to the sudoers entry which allows...
Code: Select all
/etc/scripts/*
./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
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.
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.