Sponsored Content
Top Forums Shell Programming and Scripting Help with a rotate log script Post 302697429 by 244an on Thursday 6th of September 2012 07:47:27 PM
Old 09-06-2012
Quote:
Originally Posted by newbie_01
...
BTW, just noted, I actually need to do the re-order/re-numbering before doing the rotate, not after ....
Don't know if you mean that you want help with this, bur here is a suggestion, I kept your syntax (with small adjustments) because I have never used ksh.
Code:
#!/bin/ksh
file_to_rotate=${1}
max=${2}
let curr=1
while [[ ${curr} -lt ${max} ]]; do
  if [[ ! -f ${file_to_rotate}.${curr} ]]; then
    let next=${curr}+1
    while [[ ${next} -le ${max} ]]; do
      if [[ -f ${file_to_rotate}.${next} ]]; then
        mv ${file_to_rotate}.${next} ${file_to_rotate}.${curr}
        let next=${max}+1 # don't know about ksh, if you can use break here instead
      else
        let next=${next}+1
      fi
    done
  fi
  let curr=${curr}+1
done

In your script in your first post I would have preferred mv x y instead of cp -p x y, on both places where you do the copy. For the first occurrence the "file_to_rotate" is not "rotated", it is copied to "file_to_rotate.1" but "file_to_rotate" still remains.
For second occurrence it will be the same result at the end, but if the script for some reason crashes in the middle you will have a confusing copy.

Last edited by 244an; 09-07-2012 at 08:19 AM..
 

10 More Discussions You Might Find Interesting

1. HP-UX

Check size and rotate log script.

Hi Can you suggest some perl script. My OS is HP-UX 11.11 I want to it into a cron job. Every night it will backup the file with that day's date and open a dummy file. Thanks Ash (3 Replies)
Discussion started by: ashishT
3 Replies

2. Shell Programming and Scripting

how to rotate log files

hi friends i need a shell script to rotate the logs in a directory, dated n days back. can anybody of help. appreciate.. (0 Replies)
Discussion started by: satya_skm
0 Replies

3. UNIX for Advanced & Expert Users

log rotate

hi , what is the meaning of log rotate? how do i rotate /var/adm/wtmps log and gzip it? (6 Replies)
Discussion started by: cromohawk
6 Replies

4. Shell Programming and Scripting

Script for Log Rotate

Hello, I only know the basic for shell programing. I need help for this, I thinks this is a basic for anyone who know a litle of shell scripting. I need creat a script for a rotatate logs, when a filesystem is full. I have a filesystem. The rotate consist in zip the current log (copy) and... (1 Reply)
Discussion started by: El Rengo
1 Replies

5. Shell Programming and Scripting

cron script to rotate log files

I have a mac server. I have been having problems with my logs. My hard disk became full, when i researched into why it was full it was due to massive log files. There was barley any log rotation policies in place on the server. I tired to use logrotate. This doesn't work on my server. It is a MAC... (19 Replies)
Discussion started by: timgolding
19 Replies

6. Shell Programming and Scripting

Rotate log files

I have a big log,separated by the character:, one of the fields is the date in the format "day / month / year" and I need to remove the lines prior to 30 days. Can help me? (7 Replies)
Discussion started by: msanbrug
7 Replies

7. Shell Programming and Scripting

Rotate log everyday on existing script

quick question: I have a current script that will put the output on a log file. See snapshot of the code below. I wanted this to be rotated everyday based on date. So if anyone execute the script today there will be a filecreated such as sys.log.(datetoday), if tomorrow it would be... (1 Reply)
Discussion started by: lhareigh890
1 Replies

8. Shell Programming and Scripting

"Customized" log rotate script - some advice please

Hi, Am trying to write my own version of a log rotate scripts 'coz I don't have the logrotate for other flavors of *nix servers. Probably should try and download the source and re-compile but our SA don't want to do so. Anyway, just want to know if there is any way to improve on the code... (0 Replies)
Discussion started by: newbie_01
0 Replies

9. Shell Programming and Scripting

Script to rotate file log

Hi Experts, I have script on crontab and give output quite large. I would like to know how to create rotate log when the size of log maximum 50MB if the test.log is 50MB then create test.0 Thanks Edy (2 Replies)
Discussion started by: edydsuranta
2 Replies

10. Shell Programming and Scripting

Log rotate

Hi, I have below script in logrotate.d to rotate logs. logs are not rotating after the file grow to 1k, do you have any idea? Is it because of it just only 1K? Please let me know if the below syntax is in correct. # more trotate /sourcepath/*/servers/*/logs/*log... (2 Replies)
Discussion started by: lpprasad321
2 Replies
nvlist_next_nvpair(3NVPAIR)				 Name-value Pair Library Functions			       nvlist_next_nvpair(3NVPAIR)

NAME
nvlist_next_nvpair, nvpair_name, nvpair_type - return data regarding name-value pairs SYNOPSIS
cc [ flag... ] file... -lnvpair [ library... ] #include <libnvpair.h> nvpair_t *nvlist_next_nvpair(nvlist_t *nvl, nvpair_t *nvpair); char *nvpair_name(nvpair_t *nvpair); data_type_t nvpair_type(nvpair_t *nvpair); PARAMETERS
nvl The nvlist_t to be processed. nvpair Handle to a name-value pair. DESCRIPTION
The nvlist_next_nvpair() function returns a handle to the next nvpair in the list following nvpair. If nvpair is NULL, the first pair is returned. If nvpair is the last pair in the nvlist, NULL is returned. The nvpair_name() function returns a string containing the name of nvpair. The nvpair_type() function retrieves the value of the nvpair in the form of enumerated type data_type_t. This is used to determine the appropriate nvpair_*() function to call for retrieving the value. RETURN VALUES
Upon successful completion, nvpair_name() returns a string containing the name of the name-value pair. Upon successful completion, nvpair_type() returns an enumerated data type data_type_t. Possible values for data_type_t are as follows: o DATA_TYPE_BOOLEAN o DATA_TYPE_BOOLEAN_VALUE o DATA_TYPE_BYTE o DATA_TYPE_INT8 o DATA_TYPE_UINT8 o DATA_TYPE_INT16 o DATA_TYPE_UINT16 o DATA_TYPE_INT32 o DATA_TYPE_UINT32 o DATA_TYPE_INT64 o DATA_TYPE_UINT64 o DATA_TYPE_STRING o DATA_TYPE_NVLIST o DATA_TYPE_BOOLEAN_ARRAY o DATA_TYPE_BYTE_ARRAY o DATA_TYPE_INT8_ARRAY o DATA_TYPE_UINT8_ARRAY o DATA_TYPE_INT16_ARRAY o DATA_TYPE_UINT16_ARRAY o DATA_TYPE_INT32_ARRAY o DATA_TYPE_UINT32_ARRAY o DATA_TYPE_INT64_ARRAY o DATA_TYPE_UINT64_ARRAY o DATA_TYPE_STRING_ARRAY o DATA_TYPE_NVLIST_ARRAY Upon reaching the end of a list, nvlist_next_pair() returns NULL. Otherwise, the function returns a handle to next nvpair in the list. These and other libnvpair(3LIB) functions cannot manipulate nvpairs after they have been removed from or replaced in an nvlist. Replacement can occur during pair additions to nvlists created with NV_UNIQUE_NAME_TYPE and NV_UNIQUE_NAME. See nvlist_alloc(3NVPAIR). ERRORS
No errors are defined. EXAMPLES
Example 1 Example of usage of nvlist_next_nvpair(). /* * usage of nvlist_next_nvpair() */ static int edit_nvl(nvlist_t *nvl) { nvpair_t *curr = nvlist_next_nvpair(nvl, NULL); while (curr != NULL) { int err; nvpair_t *next = nvlist_next_nvpair(nvl, curr); if (!nvl_check(curr)) if ((err = nvlist_remove(nvl, nvpair_name(curr), nvpair_type(curr))) != 0) return (err); curr = next; } return(0); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +----------------------------+------------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +----------------------------+------------------------------+ |Interface Stability | Evolving | +----------------------------+------------------------------+ |MT-Level | MT-Safe | +----------------------------+------------------------------+ SEE ALSO
libnvpair(3LIB), nvlist_alloc(3NVPAIR), attributes(5) NOTES
The enumerated nvpair data types might not be an exhaustive list and new data types can be added. An application using the data type enu- meration, data_type_t, should be written to expect or ignore new data types. SunOS 5.11 2 Feb 2004 nvlist_next_nvpair(3NVPAIR)
All times are GMT -4. The time now is 09:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy