0

I have a script running with cronjob, right now it's not working with cronjob.

If I run script manually via SSH, it requires a password and script working with password. How can I get past the password requirement and get it to work in cronjob?

This script is on server 1 and MYSQL on server 2, both are on the same local network and use UBUBTU.

backup.sh: ...

#!/bin/bash
PRIMARY=10.201.**.**
BACKUPDIR=/home/backuser/backups
FILENAME="daily-sql-$(date +%F-%H.%M).sql.xz"
ssh ${PRIMARY} "sudo mysqldump --single-transaction --quick --no-autocommit -uMysqluser -pMyslpass dbasese | xz" > $BACKUPDIR/$FILENAME

...

Henrik
  • 3
  • 2
  • 1
    Does this answer your question? [How to perform a mysqldump without a password prompt?](https://stackoverflow.com/questions/9293042/how-to-perform-a-mysqldump-without-a-password-prompt) – Rownum Highart Dec 22 '21 at 08:46
  • I can not get that solution together with my script. Maybe not working with ssh? – Henrik Dec 23 '21 at 13:20
  • SSH should not be the problem. Did you replace your command (mysqldump --single-transaction --quick --no-autocommit -uMysqluser -pMyslpass dbasese | xz) with an example from the link? What was the system's response? – Rownum Highart Dec 23 '21 at 13:28
  • I tried on two different suggestions but the password request still comes. I have also tried to create my.cnf with user / pass and it did not work either. This i use now and dont work without insert password ... ssh ${PRIMARY} "sudo mysqldump --user='***' --password='***' --single-transaction --quick --no-autocommit --databases db1 db2 | xz" > $BACKUPDIR/$FILENAME – Henrik Dec 23 '21 at 13:43
  • "I have also tried to create my.cnf with user / pass and it did not work either" - how exactly didn't it work? was there any error message? did you use the parameter --defaults-file as instructed in the example? did you put the appropriate permissions on .my.cnf? (Pay attention, .my.cnf and not my.cnf !) – Rownum Highart Dec 23 '21 at 13:56
  • Of course I missed the point before, it has now changed but when I ran the script manually it still asks for password, but it might work in cron without password request. – Henrik Dec 23 '21 at 14:16
  • Please check and update :) – Rownum Highart Dec 23 '21 at 14:33
  • same result, dont work with crone or SSH without password promt – Henrik Dec 27 '21 at 07:34
  • Now I have had more time to look at this. It is not mysql that wants a password but because I run this via the network as a password is requested. ssh: /var/spool/cron/crontabs/backup-test.sh Here i need to write password. How do I get rid of this? – Henrik Feb 03 '22 at 07:40

0 Answers0