tzvish
asked on
BASH & cron, creating a file and pushing content.
Hello,
I have a a cron task which runs a bash script that daily creates backup for mysql,
i want that script to create a text file and insert it the data which was generated by bash and was supposed to send to my email, the file will be later on read by a php script which checks numerous routine checks, and sums it up into an email.
Please modify the following bash script so it dumps what's supposed to be dumped into a file named backupLog. (That file will be overwritten by bash daily because of this cron script, so if there are permissions needed please add them too)
I have a a cron task which runs a bash script that daily creates backup for mysql,
i want that script to create a text file and insert it the data which was generated by bash and was supposed to send to my email, the file will be later on read by a php script which checks numerous routine checks, and sums it up into an email.
Please modify the following bash script so it dumps what's supposed to be dumped into a file named backupLog. (That file will be overwritten by bash daily because of this cron script, so if there are permissions needed please add them too)
#!/bin/bash
OUTFILE="/mnt/nas/backups/db_`date +%m_%d_%y`.gz"
MAILTO=myemail@address.com
SERVER=$(uname -n)
mysqldump -hLocalhost -uMyUser -pMyPass--opt --databases --single-transaction MyDB | gzip > $OUTFILE
MSG=$(ls -l $OUTFILE |awk '{print $5/1024/1024, "MB", $9}')
echo $MSG $(date) | mailx -s "Backups on $SERVER" $MAILTO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you use logger, output is continually appended. Log files can be rotated by logrotate (a standard utility on most systems). Any user can use logger and log files are owned by root. No need for abnormal permissions. You can configure to use your own file via /etc/syslog.conf
ASKER
Great info, thanks.
ASKER
1. what happens after content has been pushed to this file and then a day later more content is pushed, does that overwrite the file?
2. To evade permission problems do i need to create the file myself and chmod it to 755 ?