Sample Header Ad - 728x90

Why doesn't this script succeed from crontab as it does when manually run?

2 votes
1 answer
284 views
This script works when executed with doas ./backup_cron_root.sh
#!/usr/bin/bash

/usr/bin/crontab -l> "/tmp/cron.$(whoami).$(hostname)" && /bin/date>>"/tmp/cron.$(whoami).$(hostname)" &&
/usr/bin/doas -u joanna /usr/bin/cp -f "/tmp/cron.$(whoami).$(hostname)" "/home/joanna/pCloudDrive/backups" &&
/usr/bin/rm "/tmp/cron.$(whoami).$(hostname)"
where ./backup_cron_root.sh is the name of the script. When the same script is scheduled as a cronjob with doas crontab -e and * * * * * /home/joanna/backup_cron_root.sh >/tmp/cronjob.log 2>&1 it creates /tmp/cron.root.joanna-ONE-AMD-M4 which is owned by root but for some reason it does not succeed in copying it to /home/joanna/pCloudDrive/backups. Why so? Why doesn't this script succeed from crontab as it does when manually run? The content of my /etc/doas.conf is
permit joanna as root
permit root as joanna
The following is my tail of grep CRON /var/log/syslog:
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON: (root) CMD (/home/joanna/backup_cron_root.sh)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:17:22 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON: (root) CMD (/home/joanna/backup_cron_root.sh)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:01 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
Feb 26 17:18:22 joanna-ONE-AMD-M4 CRON: (CRON) info (No MTA installed, discarding output)
The content of /tmp/cronjob.log is
doas: Authentication failed
Asked by John Smith (827 rep)
Feb 26, 2023, 03:11 PM
Last activity: Feb 26, 2023, 09:31 PM