H
H
hellfleet2020-06-03 23:20:15
bash
hellfleet, 2020-06-03 23:20:15

Why does the script not work through crontab?

There is a simple script for backup

#!/bin/bash
ssh -2 [email protected] "mysqldump -uUSR -pPASS DB_NAME | gzip -9" > /media/backups/DB-LIVE-$(date +%Y-%m-%d-T%H-%M).sql.gz
ls -t1 /media/backups/ |tail -n +25| xargs rm -f

The table is dumped, all files except the last ones are

deleted
0 * * * * /opt/backup.sh

.
If you run the script manually, then everything works.
Tell me what is the problem when running it through cron.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2020-06-03
@shambler81

by default, cron does not use environment variables
in particular PATH
, so it does not know where the interpreter is located

/bin/bash/ls -t1 /media/backups/ |tail -n +25| /bin/bash/xargs rm -f

G
galaxy, 2020-06-03
@galaxy

ls -t1 /media/backups/will only print the filename, not the full path. cd is necessary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question