Script to maintain file versions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to maintain file versions
# 1  
Old 12-16-2011
Script to maintain file versions

I am developing a script to maintain 'n' number of versions of a file. The script will take a filename as a parameter and the number of versions to maintain. This basically does something like a FIFO. Here is what I developed. But something is not right. I have attached the script. Can u pls help here?
# 2  
Old 12-18-2011
why not use logrotate?
# 3  
Old 12-18-2011
As jeffsaxton stated logrotate does this (and lots more). So if it's available on your system it's worth learning how to configure and use it.

However, if it's not available and you cant get it installed, ive had a quick look at your script and identified these issues:

1) function fDisplayHelp is missing, this should probably print usage information (or help when $1=h) and exit.
2) No test for script being is called without -s or -n parameters, which have no defaults and so should be required options.
3) Script requires the service that writes to the log files to be stopped (as you cant move logs out from underneath a running process)

For 2) - Add following test after getopts processing:
Code:
[ -z "${sLogCnt}" ] && print -u2 "Option -n <cnt> is required" && fDisplayHelp "u"
[ -z "${sScpt}" ] && print -u2 "Option -s <script> is required" && fDisplayHelp "u"

For 3) - This is most likley what you mean by "something is not right".
Ensure you stop the service before calling your rotate script (and restart it after the script has moved the files).

Last edited by Chubler_XL; 12-18-2011 at 07:43 PM.. Reason: Some reformating and re-wording
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to maintain a personal password file 'safely'?

Hi all, As time progresses, the number of servers that I have to login to has grown to the hundreds. Some of the servers has NIS so I can use one single password for this group of servers. The hard part comes to when you have 20+ other servers that now require different passwords and... (4 Replies)
Discussion started by: newbie_01
4 Replies

2. Shell Programming and Scripting

Script FTP maintain error handling

Hi, I have ftp script like below How to insert an error handling, If the transfer failed then send mail to me. Actually, I just need the script to send an email if the FTP failed. How to put the email script within FTP script? Thank You Edy (5 Replies)
Discussion started by: edydsuranta
5 Replies

3. Shell Programming and Scripting

Help with korn shell script to get the latest file versions in a directory

I want to write a korn shell script to get the latest three versions for a file in the directory having lot of files with various versions (files with prefix as same but time stamp as suffix) and compress it and at the same time have to remove the remaining versions of the file (other than latest... (4 Replies)
Discussion started by: maheshbabu
4 Replies

4. Shell Programming and Scripting

Needed script to generate versions for a file and maintian them in a folder

need a shell script for the following requirement how to generate 5 versions of a file in a folder after generating them in a folder i want to maintian the past 2 versions of the file in the folder and i have to delete the the remaining. for example if i ran the script today and tommorow... (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

5. Shell Programming and Scripting

Maintain health of passwd file

Hello guys I am about to write a script that is based on "The Linux Administration Handbook" The exercise is as follows: Write a shell script to help monitor the health of the /etc/passwd file. Find entries that have UID0 Find entries that have no password (needs /etc/shadow) Find any... (4 Replies)
Discussion started by: Learn4Life
4 Replies

6. Homework & Coursework Questions

Maintain health of passwd file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hello guys I am about to write a script that is based on "The Linux Administration Handbook" The exercise is... (6 Replies)
Discussion started by: Learn4Life
6 Replies

7. UNIX for Dummies Questions & Answers

Script that will Delete and Maintain Files

Hi guys, Good day to all and Happy New Year!!! Cheers!!! I hope anyone could help/suggest me on hot to create a script that will monitor the directory where files are being dumped. I have a script in CRON that runs everyday and collect for logs with a filename of Output_$(date... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

8. UNIX for Dummies Questions & Answers

sed a file and maintain date stamp and permissions

I need to alter a file. I'm using sed then passing output to temp file then using touch -r to maintain the date but the permissions do not get preserved How can I sed a file and maintain date and permissions currently it's preserving the date but the permissions revert back to the... (3 Replies)
Discussion started by: andyatit
3 Replies

9. UNIX for Dummies Questions & Answers

maintain database script...

Hi there. i'm new user at here I need help for this. I need to write a script that maintains a database of cryptographic checksums. In other words, I need this script to check the files checksum whether the files has been modified or not. But i got no idea where to start. Hope anyone here can... (8 Replies)
Discussion started by: hihihehe
8 Replies

10. Shell Programming and Scripting

Maintain full path of a script in a var when sourcing it from a different script

Hi All, I've searched through the forum for a solution to this problem, but I haven't found anything. I have 2 script files that are in different directories. My first script, let's call it "/one/two/a.sh" looks like this: #!/bin/sh IN_DIR=`dirname $0` CUR_DIR=`pwd` cd $IN_DIR... (4 Replies)
Discussion started by: mrbluegreen
4 Replies
Login or Register to Ask a Question