![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why generate "ash and bash" different output for same bash script? | s. murat | Shell Programming and Scripting | 0 | 05-26-2008 04:19 AM |
| Passing options to a bash script | DeCoTwc | Shell Programming and Scripting | 3 | 05-20-2008 10:43 PM |
| [BASH - KSH] Passing array to a function | ripat | Shell Programming and Scripting | 3 | 04-17-2008 05:17 AM |
| How do you parse a variable in a bash script? | vertical98 | Shell Programming and Scripting | 3 | 03-18-2008 12:30 PM |
| Conversion of bash parsing script to perl? | cstovall | Shell Programming and Scripting | 2 | 10-13-2004 07:33 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi All,
I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl Code:
FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" Code:
06/05/2008-07:59 06/05/2008-07:59 06/05/2008-07:59 06/05/2008-07:59 06/05/2008-07:59 07/05/2008-07:59 07/05/2008-07:59 07/05/2008-07:59 07/05/2008-07:59 07/05/2008-07:59:server5:DISK 08/05/2008-07:59:server1:DISK 08/05/2008-07:59:server2:DISK 08/05/2008-07:59:server3:DISK 08/05/2008-07:59:server4:DISK 08/05/2008-07:59:server5:DISK it will be great if some one telle me How to pass the variable to perl properly. i am new to perl world. Thanks Arsidh Last edited by Yogesh Sawant; 05-22-2008 at 08:57 AM. Reason: added code tags |
| Forum Sponsor | ||
|
|
|
|||
|
Hi Yogesh,
Thanks for your valuable input, and Thanks for reply on it. I have included the sugeestion , you told me, But When i run it , i am not getting any data, which i want, but the comment from the file. Here is the Modified Code : =========================== #!/bin/bash FROM_DATE="04/05/2008" TO_DATE="06/05/2008" perl -ne 'print if ( $_ >= $ENV{'FROM_DATE'} && $_ <= $ENV{'TO_DATE'} )' monitor.audit exit ===================================== The output is only the commented line #Memory Usage #Check the Availability #Disk Monitor #Load Monitor #Memory Usage #Check the Availability The file monitor.audit data ==================== 04/05/2008-12:16 04/05/2008-12:16::77 04/05/2008-12:16::138 #Load Monitor 04/05/2008-12:16 04/05/2008-12:16::9.01 04/05/2008-12:16::0.39 #Memory Usage 04/05/2008-12:16 04/05/2008-12:16::18 04/05/2008-12:16::18 #Check the Availability 04/05/2008-12:32 04/05/2008-12:32::77 04/05/2008-12:32::138 #Load Monitor ============================================ Can you please , tell what i need to do Thanks Arsidh |
|
|||
|
Hi Guys,
Now have some other problem with Perl script. The solution which is given is working perfectly , if the dates are with in same month.If i give dates like this export FROM_DATE=04/05/2008 export TO_DATE=02/06/2008 perl -ne 'print if ( $_ >= "'$FROM_DATE'" && $_ <= "'$TO_DATE'" )' monitor.audit >$FINAL_DATA Then nothing is comming in the log file. monitor.audit ================== 06/05/2008-10:24: orasdfprd01:DATABASE:gecolfdsafprd :1 06/05/2008-10:24: cisdsfsdmarsp010:DATABASE:mafdsrp :1 06/05/2008-10:24: sdfsdacismarsfp011:DATABASE:dxfdslp :1 06/05/2008-10:24: alpfdscisfdfspdb053:DATABASE:mbdsfsop :1 12/05/2008-10:24: cisfsdfmasdfdsfrsp020:APPLCATION :1 12/05/2008-10:24: cisdsfdsfmarsp021:APPLCATION :1 12/05/2008-10:24: alpcsdfdsfispapp054:DISCOVER :0 12/05/2008-10:24: alpcsdfdsispapp055:DISCOVER :1 12/05/2008-10:39: orapsdafdsafrd01:DISK : 456 12/05/2008-10:39: cismdsafsdaarsp010:DISK : 77 12/05/2008-10:39: cisfsdafdsamarsp011:DISK : 138 20/05/2008-10:39: cismsdafsdaarsp020:DISK: 28 20/05/2008-10:39: cismfsdfsdarsp021:DISK: 28 20/05/2008-10:39: alpcsdfdsispapp054:DISK: 190 20/05/2008-10:39: alpcifasfsdaspapp055:DISK: 190 20/05/2008-10:39: alpcfsdafsdaispdb053:DISK: 309 02/06/2008-10:39: orasdfdsprd01:LOAD: 1.05 02/06/2008-10:39: cisdsfdsmarsp010:LOAD:2.86 02/06/2008-10:39: cissdafdsmarsp011:LOAD:0.43 02/06/2008-10:39: cismasadfsdrsp020:LOAD:0.12 02/06/2008-10:39: cismarsdfdssp021:LOAD:0.08 02/06/2008-10:39: alpcisdsfdsapapp054:LOAD:0.44 ================================ Please can any one suggest on this . |
|
|||
|
You should be aware, though, that Perl's <= and >= operators simply do numeric comparison. In other words, your script will not work without modification e.g. across a month boundary. The solution is to parse the date strings, and use the resulting raw numbers for comparison.
Oops, you noticed already. Anyway, Google for date parsing in Perl. Also perhaps read the time and date handling threads in the FAQs for these forums. |
|||
| Google UNIX.COM |