I have a few files to be backed up. I need a script to check line number of a file and if it exceeds, say 8000 lines, it will simply zip it and name it with date prefix format. I need your help.
closed as too broad by Braiam, Alvin Row, Wilf, bain, Luis Alvarado♦ Jul 29 '14 at 1:45
There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.
This script will get the line numbers, then if it is more than 7999 (greater than or equal to 8000) it will make a .tar.gz of the file.
Don't for get to chmod the script to get it to run -
The cron command would be
Thanks @Jnuk for the generator!
Here is a sample script that does what you describe
First it declares som variables,
FILENAME is the file you want to check the length of.
LINES iis the amount of lines we find i the file we check
MAXLINES is the max amount of lines we allow before making a backup.
DATE is todays date in Year-Month-Day format
BACKUP_PATH is the directory you are going to backup.
do_backup is the function that contains backup command
save the script into a file in terminal:
to make it executable
If you want to understand more of how the script works try running it with:
sh -x script_name