I am creating an automation script. As part of it, I want to add a cron job. Here's a part of the script that fails:
BACKUP_USER=backupbot SCRIPT_NAME=backup-script.sh scp -i ./ssh-key ./$SCRIPT_NAME user@server:/tmp ssh -i ./ssh-key user@server " sudo mv /tmp/$SCRIPT_NAME /home/$BACKUP_USER/bin/ && sudo chown $BACKUP_USER /home/$BACKUP_USER/bin/$SCRIPT_NAME && sudo chmod 100 /home/$BACKUP_USER/bin/$SCRIPT_NAME && sudo sed -i 's/THE_URL/'${1}'/' /home/$BACKUP_USER/bin/$SCRIPT_NAME && sudo echo '*/1 * * * *' $BACKUP_USER /home/$BACKUP_USER/bin/$SCRIPT_NAME > /etc/cron.d/discourse-backup" The problematic command is:
sudo echo '*/1 * * * *' $BACKUP_USER /home/$BACKUP_USER/bin/$SCRIPT_NAME > /etc/cron.d/discourse-backup I'm getting:
bash: line 5: /etc/cron.d/discourse-backup: Permission denied
Until this one, everything is executed as it should. What is the issue with my last command? I thought it is some problem with quotes - I tried multiple combinations of single- and double- quotes, but I ended up with the same (or worse) results.
sudo.