Re: [gentoo-user] rm: missing operand in emailed result of cron job that uses rm to remove aged files
On Mon, 20 Jan 2014 06:38:40 -0500, Tanstaafl wrote: The pertinent part of the script is: # delete aged backup files, keeping 60 nightlies and 45 (5 days of) hourlies rm $(ls -1t $MySQL_BACKUP_DIR_nightly/* | tail -n +61) rm $(ls -1t $MySQL_BACKUP_DIR_hourly/* | tail -n +46) It works fine and does what it is supposed to, but the email I get as a result of the script running says only this in the body: rm: missing operand Try 'rm --help' for more information. Do you have a file with an odd name in either of those directories, particularly one starting with a - You could try adding echo rm $(ls -1t ... to the script to see what it is actually trying to run. Or you could use find instead find $MySQL_BACKUP_DIR_nightly -type f -mtime +60 -exec rm {} + -- Neil Bothwick The trouble with life is that you are halfway through it before you realize it's a do it yourself thing. signature.asc Description: PGP signature
Re: [gentoo-user] rm: missing operand in emailed result of cron job that uses rm to remove aged files
On 2014-01-20 6:51 AM, Neil Bothwick n...@digimed.co.uk wrote: On Mon, 20 Jan 2014 06:38:40 -0500, Tanstaafl wrote: The pertinent part of the script is: # delete aged backup files, keeping 60 nightlies and 45 (5 days of) hourlies rm $(ls -1t $MySQL_BACKUP_DIR_nightly/* | tail -n +61) rm $(ls -1t $MySQL_BACKUP_DIR_hourly/* | tail -n +46) It works fine and does what it is supposed to, but the email I get as a result of the script running says only this in the body: rm: missing operand Try 'rm --help' for more information. Do you have a file with an odd name in either of those directories, particularly one starting with a - No, they are all sql.gz files, starting with the date, like: 2014-01-05_0958-hostname-all.sql.gz You could try adding echo rm $(ls -1t ... to the script to see what it is actually trying to run. Or you could use find instead find $MySQL_BACKUP_DIR_nightly -type f -mtime +60 -exec rm {} + Ok, may try that... thx...
Re: [gentoo-user] rm: missing operand in emailed result of cron job that uses rm to remove aged files
On 01/20/14 14:37, Tanstaafl wrote: On 2014-01-20 6:51 AM, Neil Bothwick n...@digimed.co.uk wrote: On Mon, 20 Jan 2014 06:38:40 -0500, Tanstaafl wrote: The pertinent part of the script is: # delete aged backup files, keeping 60 nightlies and 45 (5 days of) hourlies rm $(ls -1t $MySQL_BACKUP_DIR_nightly/* | tail -n +61) rm $(ls -1t $MySQL_BACKUP_DIR_hourly/* | tail -n +46) It works fine and does what it is supposed to, but the email I get as a result of the script running says only this in the body: rm: missing operand Try 'rm --help' for more information. Do you have a file with an odd name in either of those directories, particularly one starting with a - No, they are all sql.gz files, starting with the date, like: 2014-01-05_0958-hostname-all.sql.gz You could try adding echo rm $(ls -1t ... to the script to see what it is actually trying to run. Or you could use find instead find $MySQL_BACKUP_DIR_nightly -type f -mtime +60 -exec rm {} + Ok, may try that... thx... find -exec (or the shorter find -delete) is the preffered tool for this job. As you have it, you are blindly deleting whatever happens to show up in ls and woe betide the results on the next run if one fails. find OTOH lets you specify exactly what you want to delete rather than doing text manipulation on ls output and praying it might coincide with what you want. [been there, done that, caused catastrophic data loss, bought lots of beer as penance] -- Alan McKinnon alan.mckin...@gmail.com
Re: [gentoo-user] rm: missing operand in emailed result of cron job that uses rm to remove aged files
On 01/20/14 14:37, Tanstaafl wrote: On 2014-01-20 6:51 AM, Neil Bothwick n...@digimed.co.uk wrote: On Mon, 20 Jan 2014 06:38:40 -0500, Tanstaafl wrote: The pertinent part of the script is: # delete aged backup files, keeping 60 nightlies and 45 (5 days of) hourlies rm $(ls -1t $MySQL_BACKUP_DIR_nightly/* | tail -n +61) rm $(ls -1t $MySQL_BACKUP_DIR_hourly/* | tail -n +46) It works fine and does what it is supposed to, but the email I get as a result of the script running says only this in the body: rm: missing operand Try 'rm --help' for more information. Do you have a file with an odd name in either of those directories, particularly one starting with a - No, they are all sql.gz files, starting with the date, like: 2014-01-05_0958-hostname-all.sql.gz You could try adding echo rm $(ls -1t ... to the script to see what it is actually trying to run. Or you could use find instead find $MySQL_BACKUP_DIR_nightly -type f -mtime +60 -exec rm {} + Ok, may try that... thx... find -exec (or the shorter find -delete) is the preffered tool for this job. As you have it, you are blindly deleting whatever happens to show up in ls and woe betide the results on the next run if one fails. find OTOH lets you specify exactly what you want to delete rather than doing text manipulation on ls output and praying it might coincide with what you want. [been there, done that, caused catastrophic data loss, bought lots of beer -- Alan McKinnon alan.mckin...@gmail.com