Script solution - running Excel macro in SLES


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script solution - running Excel macro in SLES
# 8  
Old 11-19-2016
This is way more complex as it would require a full blown date time handling. Some awk versions offer functions for this, mine doesn't. You might be luckier with yours.
# 9  
Old 11-19-2016
Quote:
Originally Posted by RudiC
This is way more complex as it would require a full blown date time handling. Some awk versions offer functions for this, mine doesn't. You might be luckier with yours.
it it possible to use unix time?

Last edited by bigbrobg; 11-19-2016 at 05:32 PM..
# 10  
Old 11-19-2016
Sorry?
# 11  
Old 11-19-2016
Perl modules could be used to perform date arithmetic/comparison.
Here's a possible solution.

Code:
$ 
$ 
$ cat exitwithtimeout.txt
Day,Start Date,Start Time,End Date,End Time,Queue,Issue
Mon,07 Nov 2016,09:12:48 EST,07 Nov 2016,09:13:41 EST,2041,EXITWITHTIMEOUT,30
Mon,07 Nov 2016,09:16:42 EST,07 Nov 2016,09:17:41 EST,2081,EXITWITHTIMEOUT,30
Mon,07 Nov 2016,09:39:15 EST,07 Nov 2016,09:40:11 EST,2041,EXITWITHTIMEOUT,30
Mon,07 Nov 2016,10:17:11 EST,07 Nov 2016,10:17:41 EST,2081,EXITWITHTIMEOUT,30
Thu,17 Nov 2016,10:06:07 EST,17 Nov 2016,10:06:59 EST,2031,EXITWITHTIMEOUT,30
$ 
$ cat ringnoanswer.txt 
Day,Start Date,Start Time,End Date,End Time,Queue,Operator,Issue,WaitTime
Mon,07 Nov 2016,09:12:48 EST,07 Nov 2016,09:13:10 EST,2041,Djamila Millien,RINGNOANSWER,20000
Mon,07 Nov 2016,09:32:19 EST,07 Nov 2016,09:32:41 EST,2041,Djamila Millien,RINGNOANSWER,20000
Mon,07 Nov 2016,09:35:48 EST,07 Nov 2016,09:36:11 EST,2021,Kimberly Paz,RINGNOANSWER,20000
Mon,07 Nov 2016,09:39:15 EST,07 Nov 2016,09:39:40 EST,2041,Djamila Millien,RINGNOANSWER,20000
Mon,07 Nov 2016,10:17:11 EST,07 Nov 2016,10:17:41 EST,2081,Deidra Wright,RINGNOANSWER,20000
Thu,17 Nov 2016,10:05:53 EST,17 Nov 2016,10:06:29 EST,2021,Traci Dingman,RINGNOANSWER,20000
$ 
$ cat -n compare_datetimes.pl 
     1	#!/usr/bin/perl -w
     2	use strict;
     3	use DateTime;
     4	
     5	my %mth = qw(Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6
     6	             Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12);
     7	my (@ewt_arr, @token, @sdt, @sts, @edt, @ets);
     8	my $ewt_file = $ARGV[0];
     9	my $rna_file = $ARGV[1];
    10	
    11	# Read the exitwithtimeout file, parse and store the start and
    12	# end datetimes in the ewt_arr array.
    13	open(FH, "<", $ewt_file) or die "Can't open $ewt_file : $!";
    14	while (<FH>) {
    15	    next if $. == 1;
    16	    chomp(@token = split(/,/, $_));
    17	    @sdt = split(/ /, $token[1]);
    18	    $sdt[1] = $mth{$sdt[1]};
    19	    @sts = split(/[: ]/, $token[2]);
    20	
    21	    @edt = split(/ /, $token[3]);
    22	    $edt[1] = $mth{$edt[1]};
    23	    @ets = split(/[: ]/, $token[4]);
    24	
    25	    push (@ewt_arr, [    DateTime->new(
    26	                             year => $sdt[2],
    27	                             month => $sdt[1],
    28	                             day => $sdt[0],
    29	                             hour => $sts[0],
    30	                             minute => $sts[1],
    31	                             second => $sts[2]
    32	                         ),
    33	                         DateTime->new(
    34	                             year => $edt[2],
    35	                             month => $edt[1],
    36	                             day => $edt[0],
    37	                             hour => $ets[0],
    38	                             minute => $ets[1],
    39	                             second => $ets[2]
    40	                         )
    41	                    ]);
    42	
    43	}
    44	close(FH) or die "Can't close $ewt_file : $!";
    45	
    46	# Read the ringnoanswer file, capture the start and end datetimes
    47	# and compare with each element of ewt_arr array. If there is an
    48	# overlap, then print Queue, Operator and WaitTime values.
    49	printf("%-10s %-20s %s\n", "RNA Queue","RNA Operator","RNA WaitTime");
    50	open(FH, "<", $rna_file) or die "Can't open $rna_file : $!";
    51	while (<FH>) {
    52	    next if $. == 1;
    53	    chomp(@token = split(/,/, $_));
    54	    @sdt = split(/ /, $token[1]);
    55	    $sdt[1] = $mth{$sdt[1]};
    56	    @sts = split(/[: ]/, $token[2]);
    57	
    58	    @edt = split(/ /, $token[3]);
    59	    $edt[1] = $mth{$edt[1]};
    60	    @ets = split(/[: ]/, $token[4]);
    61	
    62	    my $sdate = DateTime->new(
    63	                    year => $sdt[2],
    64	                    month => $sdt[1],
    65	                    day => $sdt[0],
    66	                    hour => $sts[0],
    67	                    minute => $sts[1],
    68	                    second => $sts[2]
    69	                );
    70	    my $edate = DateTime->new(
    71	                    year => $edt[2],
    72	                    month => $edt[1],
    73	                    day => $edt[0],
    74	                    hour => $ets[0],
    75	                    minute => $ets[1],
    76	                    second => $ets[2]
    77	                );
    78	    foreach my $item (@ewt_arr) {
    79	        if ( DateTime->compare($edate, $item->[0]) >= 0 and
    80	             DateTime->compare($sdate, $item->[1]) <= 0 ) {
    81	            printf("%-10s %-20s %s\n", $token[5], $token[6], $token[8]);
    82	        }
    83	    }
    84	}
    85	close(FH) or die "Can't close $rna_file $!";
    86	
$ 
$ perl compare_datetimes.pl exitwithtimeout.txt ringnoanswer.txt
RNA Queue  RNA Operator         RNA WaitTime
2041       Djamila Millien      20000
2041       Djamila Millien      20000
2081       Deidra Wright        20000
2021       Traci Dingman        20000
$ 
$

I should've added script comments for lines 79 and 80.
Basically, if we have two date intervals like so:

[sd1, ed1] ==> date interval with start date sd1 and end date ed1
[sd2, ed2] ==> date interval with start date sd2 and end date ed2

then an "overlap" occurs if the following condition is true:

ed2 >= sd1 and sd2 <= ed1

I capture [sd2, ed2] in each line of ringnoanswer.txt and compare that interval with
the one stored in ewt_arr array. Each element of ewt_arr is an array reference with the
first element being sd1 and the second element being ed1.

Last edited by durden_tyler; 11-19-2016 at 01:22 PM..
This User Gave Thanks to durden_tyler For This Post:
# 12  
Old 11-19-2016
Quote:
Originally Posted by RudiC
Sorry?

Maybe I can use these:

Code:
1479585616|1479585585.136581|2041|NONE|EXITWITHTIMEOUT|1|1|30
1479585687|1479585657.136613|2031|NONE|EXITWITHTIMEOUT|1|1|30
1479586178|1479586148.136659|2081|NONE|EXITWITHTIMEOUT|1|1|30
1479587086|1479587055.136842|2011|NONE|EXITWITHTIMEOUT|1|1|30

1479586178|1479586148.136659|2081|Mary Ellen Buckley|RINGNOANSWER|5000
1479587070|1479587055.136842|2011|Nashid Ali|RINGNOANSWER|14000
1479587073|1479587055.136842|2011|Mary Ellen Buckley|RINGNOANSWER|17000
1479587086|1479587055.136842|2011|Nashid Ali|RINGNOANSWER|8000
1479587717|1479587697.136936|2021|Traci Dingman|RINGNOANSWER|20000

# 13  
Old 11-20-2016
OK, that should be much easier. How come the start time is later than the end time in all cases above? And, which time (start or end) of
Quote:
RingNoAnswer between Start-End time of ExitWithTimeout
should be considered?
This User Gave Thanks to RudiC For This Post:
# 14  
Old 11-20-2016
Let's assume $1 is the epoch time to be considered - try
Code:
awk -F"|" '
NR == FNR       {EN[$1] = $2
                 next
                }

BEGIN   {print "RNA Queue   RNA Operator   RNA WaitTime"
        }

        {for (e in EN) if ($1 <= e && $1 >= EN[e]) print $3, $4, $6
        }
' file2 file1
RNA Queue   RNA Operator   RNA WaitTime
2081 Mary Ellen Buckley 5000
2011 Nashid Ali 14000
2011 Mary Ellen Buckley 17000
2011 Nashid Ali 8000

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting macro to bash script

Gents, Please can you help me with this. When column 49 == 2 Before X 4714 14710 69445.00 19257.001 1218 12271 69596.00 19460.00 19478.001 X 4714 14710 69445.00 19257.001 1228 12292 69596.00 19480.00 19480.001 After X 4714 14710 69445.00 19257.001 1218... (1 Reply)
Discussion started by: jiam912
1 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Perl script to Merge contents of 2 different excel files in a single excel file

All, I have an excel sheet Excel1.xls that has some entries. I have one more excel sheet Excel2.xls that has entries only in those cells which are blank in Excel1.xls These may be in different workbooks. They are totally independent made by 2 different users. I have placed them in a... (1 Reply)
Discussion started by: Anamika08
1 Replies

4. Shell Programming and Scripting

Invoke a script in UNIX using Excel Macro

Hi, I am using Send Keys to connect to UNIX server and invoke a script . Is there an alternate way to connect to UNIX server using Excel macro and invoke a UNIX Shell script? Anu (2 Replies)
Discussion started by: anandita.jha
2 Replies

5. SuSE

SLES 9 vs SLES 11 hard drive cache read timings are diffrent

Can anyone give me a little clue on why the hard drive cache read timings on sles 9 is better then sles 11? The same hardware was used in both test. I even deleted the ata_generic module from initrd. The speed difference is 10MB vs 5 MB Thanks (1 Reply)
Discussion started by: 3junior
1 Replies

6. Programming

Make-question - redefine a macro, using another macro..?

I think there is no problem to use any macro in a new macro definishion, but I have a problem with that. I can not understand why? I have a *.mak file that inludes file with many definitions and rules. ############################################## include dstndflt.mak ... One of the... (2 Replies)
Discussion started by: alex_5161
2 Replies

7. Shell Programming and Scripting

How to launch a Csh shell script using Excel Macro ?

Hi all. I need to use excel macro at my desktop to launch a csh script which is in a solaris environment. What is the code that i can use in macro to help me with that ? Basically, the code need to telnet or ftp to the solaris environment and just run the script and the macro will output in an... (1 Reply)
Discussion started by: Raynon
1 Replies

8. UNIX for Dummies Questions & Answers

macro on shell script ?

in shifts we used to run a script where in we need to choose from different options. for example the first part would go like this: ======== menu ======== 1)blah 2)blah blah 3)blah blah blah you have chosen: then after that a series of multiple choice so on and so forth...what i would... (4 Replies)
Discussion started by: inquirer
4 Replies
Login or Register to Ask a Question