Solved Cron job issue not working..

November 20, 2012 at 02:02:44
Specs: Linux centos
I setup a script for to take an mysql db backup everyday on a specific time, so now the cron is running perfectly it executing the script without problem but the problem is db backup file is not stored in the specific location,but while we executing a script manually in terminal it executing and the files are stored in the specific location perfectly.

I checked the cron logs it's shows all perfectly running, and i check the cron and mysql status it's running perfectly.

help me to solve this issue.


See More: Cron job issue not working..

Report •

✔ Best Answer
November 21, 2012 at 02:33:43
we mentioned this /tmp/.backup_out.txt location in this script. Before while we executing a script it shows permission denied issue.Now the problem could be solved.


#1
November 20, 2012 at 02:18:29
Did you code the full path where the backup has to be stored?

Beware absolute locations must be coded in a skeduled script since current directory is not the same as while executing at terminal window.


Report •

#2
November 20, 2012 at 02:22:47
No both the directories are could be same.while i am executing script manually or the cron running the script. the problem is this issue is to be happened in very recently.but before days it could working fine.

Report •

#3
November 20, 2012 at 02:41:35
Please, I suggest you post the script since a look at its code is needed to go further.

Report •

Related Solutions

#4
November 20, 2012 at 02:45:13
#!/bin/bash

backup() {
export FILE=`date +'%Y%m%d_%H'`
export DT=`date +'%d-%m-%Y_%H_%M'`
LASTWEEKDATE=`date -d '7 days ago' '+%Y%m%d_%H'`

echo "Starting MySql Backup"
mysqldump --all-databases -u root -p9ENj5UP > /srv/deve/db_backups/server_daily/DB_SERVER_BACKUP_$FILE.sql
echo "Completed MySql Backup"

echo "Starting Backup Compression"
gzip /srv/deve/db_backups/server_daily/DB_SERVER_BACKUP_$FILE.sql
echo "Completed Backup Compression to /srv/deve/db_backups/server_daily/DB_SERVER_BACKUP_$FILE.sql"

echo "Removing last week backup file.."
rm -f /srv/deve/db_backups/server_daily/DB_SERVER_BACKUP_$FILE.sql
echo "Completed removing last week backup file ."
}

exit;


Report •

#5
November 20, 2012 at 02:56:22
Mmh...

May you explain better the wrong location issue, i.e. where the backup is actually stored instead the location expected. Is the wrong location always the same or randomly selected?


Report •

#6
November 20, 2012 at 03:06:47
Sorry i didn't understand.

Report •

#7
November 20, 2012 at 03:12:59
Where is the backup file stored and is that (wrong) location always the same?

Report •

#8
November 20, 2012 at 05:03:27
backup files are stored in this location only "/srv/deve/db_backups/server_daily"

Report •

#9
November 20, 2012 at 08:25:35
First, I would try defining the PATH in your script. Use the PATH definition you are using when running from the command line (terminal mode)

Second, maybe you are having a file permission problem. Are you using the same user to execute the script from cron? With the PATH variable defined, you might try executing from root's cron to see if that works.

Third, if that still doesn't work, check the exit code, $?, after the mysqldump, the gzip, or any other external Linux command to see which one is failing.

mysqldump ....
if [[ $? -eq 0 ]]
then
   echo "command worked"
fi



Report •

#10
November 20, 2012 at 08:40:47
The location you report is exactly where your compression command does store the result

gzip /srv/deve/db_backups/server_daily/DB_SERVER_BACKUP_$FILE.sql

i.e. as /srv/deve/db_backups/server_daily/DB_SERVER_BACKUP_$FILE.sql.gz
so, if you want another directory, issue a move command for the compressed .gz file.

Report •

#11
November 21, 2012 at 02:22:33
cron issue solved....Thanks for the response..

Report •

#12
November 21, 2012 at 02:29:26
Please, report the solution you found so other users can share that.

Report •

#13
November 21, 2012 at 02:32:00
file permission problem in /tmp/.backup_out.txt.i just modified the permission now the cron is running perfectly and the file is storing in perfect location.

Report •

#14
November 21, 2012 at 02:33:43
✔ Best Answer
we mentioned this /tmp/.backup_out.txt location in this script. Before while we executing a script it shows permission denied issue.Now the problem could be solved.

Report •

Ask Question