Sponsored Content
Top Forums Shell Programming and Scripting Getting previous hour in formatted form Post 302511119 by Amutha on Wednesday 6th of April 2011 03:05:22 AM
Old 04-06-2011
Quote:
Originally Posted by methyl
Why is the parameter value "6" ?
Do you mean:
Please list all the files you would expect to search when the parameter is value "6".

yes what you meant is rite. i need to get the list like this. the duration might be different and the date also might be different depending upon the user is passing it.

---------- Post updated 04-06-11 at 02:05 AM ---------- Previous update was 04-05-11 at 11:34 PM ----------

Quote:
Originally Posted by Chubler_XL
If you have GNU date (accepts -d), this should do it.

Convert date+time to epoch time using %s format (seconds past epoch date).
Once you have the date+time as epoch time you can navigate forwards and backwards by just adding or subtracting the number of secs required (eg 3600 for 1 hour).
Use the GNU -d @<epochsecs> parameter to convert back to the display format.

Code:
FMT=$( echo $1 | sed -e 's/\(.*\)-\(.*\)/\1 \2:00/')
SECS=$(date -d "$FMT" +%s)
COUNT=$2
while [ $COUNT -gt 0 ]
do
   echo logfilename.$(date -d "@$SECS" +%Y-%d-%m-%H)
   let SECS=SECS+3600
   let COUNT=COUNT-1
done


Hi Chuble,

Thank you so much.. i got what i need..
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Changing Unix form to Microsoft Word form to be able to email it to someone.

Please someone I need information on how to change a Unix form/document into a microsoft word document in order to be emailed to another company. Please help ASAP. Thankyou :confused: (8 Replies)
Discussion started by: Cheraunm
8 Replies

2. UNIX for Dummies Questions & Answers

an hour less in 24 hour system

My program: __________________________________ #!/bin/ksh DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` day=`date +%m/%d/%y` let h=$H-1 echo DAY $DAY echo H $H echo M $M echo day $day echo h $h _____________________________________ My result: (3 Replies)
Discussion started by: bobo
3 Replies

3. Shell Programming and Scripting

Formatted Output

Hi I have the following lines in a file SWPRC000001NOT STATED 1344 SWPRC000001NOT STATED 1362 SWPRC000001NOT STATED 1418 SWPRC000001NOT STATED 1436 SWPRC000001NOT STATED ... (6 Replies)
Discussion started by: dhanamurthy
6 Replies

4. Shell Programming and Scripting

More formatted string

In a large file i need last line of the file but I want ignore first charcter, ignore leading zeros after first character and print the remaining character as such. Is something i can do it by tail or wc? cat test1 .... ...... 8000003687 cat test2 .... ...... 8000538990 o/p 3687 538990 (3 Replies)
Discussion started by: ford2020
3 Replies

5. Shell Programming and Scripting

Show previous hour

date +%Y%m%d%H output : 2011031415 I want to get previous hour like this 2011031414. Any one can help ? (15 Replies)
Discussion started by: alvin0618
15 Replies

6. Shell Programming and Scripting

Transpose Data form Different form

HI Guys, I have data in File A.txt RL03 RL03_A_1 RL03_B_1 RL03_C_1 RL03 -119.8 -119.5 -119.5 RL07 RL07_A_1 RL07_B_1 RL07_C_1 RL07 -119.3 -119.5 -119.5 RL15 RL15_A_1 RL15_C_1 RL15 -120.5 -119.4 RL16... (2 Replies)
Discussion started by: asavaliya
2 Replies

7. Shell Programming and Scripting

Remove x lines form top and y lines form bottom using AWK?

How to remove x lines form top and y lines form bottom. This works, but like awk only cat file | head -n-y | awk 'NR>(x-1)' so remove last 3 lines and 5 firstcat file | head -n-3 | awk 'NR>4' (5 Replies)
Discussion started by: Jotne
5 Replies

8. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

9. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies
acctcom(8)						      System Manager's Manual							acctcom(8)

NAME
acctcom - Displays selected process accounting record summaries SYNOPSIS
/usr/bin/acctcom [-abfhikmqrtv] [-C seconds] [-e time] [-E time] [-g group] [-H factor] [-I number] [-l line] [select_flag -o file] [-n pattern] [-O seconds] [-s time] [-S time] [-u username] [file ...] FLAGS
Displays average statistics about the selected processes. Statistics are displayed at the end of the output records in the format var=# (for example, CMDS=439), where the value (#) is given to the nearest hundredth. The var specifies the following: Value Total number of commands listed in the specified file Average real time per process Average CPU time per process Average user CPU time per process Average system CPU time per process Average number of characters transferred Average number of blocks transferred Average CPU factor (average user time divided by total CPU time) Average hog factor (average CPU time divided by average elapsed time) Displays information about the most recently executed commands first. This flag has no effect when the acctcom command reads from the default input device or if more than one process accounting file is specified. The column heading format is the same as the default column heading format. Lists processes whose total CPU time (system time + user time) is greater than the value specified by seconds. The column heading format is the same as the default column heading format. Displays information only about processes that start at or before the specified time, which is specified as hh[:mm[:ss]]. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy START BEFORE: day mon date hh:mm:ss yy COMMAND START END REAL CPU MEAN NAME USER TTYNAME TIME TIME (SECS) (SECS) SIZE(K) Displays information only about processes that end at or before the specified time, which is specified as hh[:mm[:ss]]. If you specify the same time for both the -E and -S flags, the acctcom command displays processes that existed at the specified time. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy END BEFORE : day mon date hh:mm:ss yy COMMAND START END REAL CPU MEAN NAME USER TTYNAME TIME TIME (SECS) (SECS) SIZE(K) Displays information about the fork/exec flag (used to execute another process) in the F column and the system exit value STAT, which can be zero (0) or an error code, in the STAT column in addition to the default column heading format. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy COMMAND START END REAL CPU MEAN NAME USER TTYNAME TIME TIME (SECS) (SECS) SIZE(K) F STAT Displays only the processes that belong to the specified group. You may specify either the group ID or the group name. The column heading format is the same as the default column heading format. Displays the hog factor instead of the mean memory size. The hog factor is the CPU time used by the process divided by the real time. The output is the same as the default column format output except the MEAN SIZE(K) column heading is replaced by the .HOG FACTOR heading. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy COMMAND START END REAL CPU HOG NAME USER TTYNAME TIME TIME (SECS) (SECS) FACTOR Displays information about processes that exceed the value specified by the hogfactor variable. The output format is the same as the default column heading format. Displays the number of characters and blocks transferred during read or write I/O operations. The output is similar to the default column heading format, except the CHARS TRANSFD column replaces the MEAN SIZE(K) column, and the BLOCKS READ column is added to the output. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy COMMAND START END REAL CPU CHARS BLOCKS NAME USER TTYNAME TIME TIME (SECS) (SECS) TRANSFD READ Displays information about the processes that transfer more than the number of characters specified by the number variable. The output format is the same as the default column heading format. Displays the total number of K-core min- utes, which is the number of kilobytes of memory used by the process multiplied by the buffer time used. The output format is the same as the default column heading format, except the KCORE MIN column heading replaces the MEAN SIZE(K) column heading. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy COMMAND START END REAL CPU KCORE NAME USER TTYNAME TIME TIME (SECS) (SECS) MIN Displays information about the processes that belong to the workstation whose tty line is specified by the line variable (for example, ttyp0). The heading format is the same as the default column heading format. Displays the median amount of process memory used. If you also specify the -h or -k flag, the -m flag is ignored. The output format is the same as the default column heading format. Displays information only about the processes whose names include the regular expression specified by the pattern variable. The output format is the same as the default column heading format. Copies selected process records to the specified filename. The select_flag variable specifies the following process selection flags: -C, -e, -E, -g, -H, -I, -l, -n, -O, -s, -S, and -u. If you do not specify a selection flag with the select_flag variable, all process records are copied to filename. The output format includes only the date and time: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy Displays information about the processes that have a CPU system time exceeding the time specified by the seconds variable. The output format is the same as the default column heading format. Displays only the average statistics, which are shown at the end of the command output when you use the -a flag. Displays the CPU factor, which is the user time divided by the total CPU time. The output format is the same as the default column heading format, except the CPU FACTOR column replaces the MEAN SIZE(K) column. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy COMMAND START END REAL CPU CPU NAME USER TTYNAME TIME TIME (SECS) (SECS) FACTOR Displays information about the processes that existed on or after time, which is specified as hh[:mm[:ss]]. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy END AFTER : day mon date hh:mm:ss yy COMMAND START END REAL CPU MEAN NAME USER TTYNAME TIME TIME (SECS) (SECS) SIZE(K) Displays information only about the processes that started at or after time, which is specified as hh[:mm[:ss]]. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy START AFTER : day mon date hh:mm:ss yy COMMAND START END REAL CPU MEAN NAME USER TTYNAME TIME TIME (SECS) (SECS) SIZE(K) Displays system and user CPU times under separate column headings. The CPU SYS column heading, which shows the system CPU time, replaces the CPU (SECS) default column heading. The column heading format is as follows: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yy COMMAND START END REAL CPU (SECS) NAME USER TTYNAME TIME TIME (SECS) SYS USER Displays information about the processes that are owned by user username. You can specify a user identification number, a login name converted to a user identification number, a number sign (#) to specify root or a question mark (?), which selects pro- cesses associated with unknown user identification numbers. The output format is the same as the default column heading format. Removes column headings from the output; otherwise the output is the same as the default column heading format. DESCRIPTION
The acctcom command displays process accounting records from files specified by the file parameter, from standard input, or from the /var/adm/pacct file. If you do not specify a file and if standard input is assigned to a workstation or to /dev/null (for example, if a process runs in the background), the acctcom command reads the /var/adm/pacct file. You do not have to be root to use the acctcom command, which is located in the /usr/bin directory. If you specify more than one filename, the acctcom process reads each file chronologically in time-descending order according to process completion time. Usually, the /var/adm/pacct file is used, but you can have several /var/adm/pacct/*Vn files, which are created by the ckpacct command. Each record specifies the execution times for a completed process. The default output format includes the command name, user name, tty name, process start time, process end time, real seconds, CPU seconds, and mean memory size (in kilobytes). The process summary output has the following default column heading format: ACCOUNTING RECORDS FROM: day mon date hh:mm:ss yyyy COMMAND START END REAL CPU MEAN NAME USER TTYNAME TIME TIME (SECS) (SECS) SIZE(K) If a specified time is later than the current time, it is interpreted as occurring on the previous day. You can use flags to display the state of the fork/exec flag, F column; the system exit value, STAT column; the ratio of total CPU time to elapsed time, HOG FACTOR column; the product of memory used and elapsed time, KCORE MIN column; the ratio of user time to total (system plus user) time, CPU FACTOR column; the number of characters transferred during I/O operations, CHARS TRNSFD column; and the total number of blocks read or written, BLOCKS READ column. If a process is run under root or su authority, the command name is prefixed with a number sign (#). If a process is not assigned to a known tty (for example, if the cron daemon runs the process), a question mark (?) is displayed in the TTYNAME column. The acctcom command reports only on processes that have completed. Use the ps command to examine the status of active processes. For any flag value that produces a timestamp in an output heading, the order of date and time information is locale dependent. The time- stamps shown in the examples use the default format for date and time values. EXAMPLES
The following command displays information about processes that exceed 2.0 seconds of CPU time: /usr/sbin/acct/acctcom -O 2 < /var/adm/pacct The following command displays information about processes belonging to the Finance group: /usr/sbin/acct/acctcom -g Finance < /var/adm/pacct The following command displays information about processes belonging to tty /dev/console that run after 5:00 p.m.: /usr/sbin/acct/acctcom -l /dev/console -s 17:00 FILES
Specifies the command path. The active process accounting database file. User and group database files. Accounting header files that define formats for writing accounting files. RELATED INFORMATION
Commands: ed(1), ps(1), su(1), acct(8), cron(8), runacct(8) Functions: acct(2) delim off acctcom(8)
All times are GMT -4. The time now is 08:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy