Answer the question
In order to leave comments, you need to log in
Does it work through the console, does it work with cron?
crontab -e:
There 30 13 * * * /home/backup/delete.sh bitmirpack /home/backup >> /tmp/debug_cron 2>&1
script delete.sh
#!/bin/bash
SAVE_LIMIT=2
kernel_name=$1
backup_dir=$2
# clean old backup
clean_old_backup_files(){
LIMIT_DAYS=$(date -d "$SAVE_LIMIT day ago" +%d.%m.%Y)
TAR_OLD=$(find $backup_dir -name "www_backup_${kernel_name}_${LIMIT_DAYS}.tar.gz" | wc -l)
if ; then
rm -f "www_backup_${kernel_name}_${LIMIT_DAYS}.tar.gz"
fi
SQL_OLD=$(find $backup_dir -name "mysql_dump_${kernel_name}_${LIMIT_DAYS}.sql" | wc -l)
if ; then
rm -f "mysql_dump_${kernel_name}_${LIMIT_DAYS}.sql"
fi
SQL_AFTER_CONNECT_OLD=$(find $backup_dir -name "mysql_dump_${kernel_name}_${LIMIT_DAYS}_after_connect.sql" | wc -l)
if ; then
rm -f "mysql_dump_${kernel_name}_${LIMIT_DAYS}_after_connect.sql"
fi
}
clean_old_backup_files
Answer the question
In order to leave comments, you need to log in
1. By the modification date of the /tmp/debug_cron file, understand whether the job from cron starts at all or not.
2. If the task starts, after #!/bin/bash enter the line
set -x
In the log we will see which commands were executed with which arguments.
If a part of a large script is given, then it must be taken into account that the environment (env) in cron is different from the environment in the terminal. Maybe some variables are missing.... Although the script seems to be simple...
3. Relative names are used in the script. The current directory for a cron job may be different.
In the script, add the line at the beginning: cd <desired directory>
Most likely a problem with environment variables
where should the script look for bitmirpack?
A recent article on Habré is just about this
Does it work through the console, does it work with cron?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question