We help IT Professionals succeed at work.

BASH & cron, creating a file and pushing content.

tzvish
tzvish asked
on
686 Views
Last Modified: 2012-05-06
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)
#!/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

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Maciej Ssysadmin
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Duncan RoeSoftware Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, but

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 ?
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Duncan RoeSoftware Developer
CERTIFIED EXPERT

Commented:
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

Author

Commented:
Great info, thanks.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.