The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2008
Registered User
 

Join Date: May 2008
Posts: 6
Exclamation passing variable from bash to perl from bash script

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"
filename has following data :-
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
if we hard code the values of FROM_DATE and TO_DATE it is working.I feel what to know why it is not working When i passing it as variable.
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-22-2008
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 758
replace $FROM_DATE with $ENV{'FROM_DATE'}

replace $TO_DATE with $ENV{'TO_DATE'}
Reply With Quote
  #3 (permalink)  
Old 05-22-2008
Registered User
 

Join Date: May 2008
Posts: 6
Exclamation passing variable from bash to perl from bash script

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:16r:453
04/05/2008-12:16::77
04/05/2008-12:16::138
#Load Monitor
04/05/2008-12:16ra:0.39
04/05/2008-12:16::9.01
04/05/2008-12:16::0.39
#Memory Usage
04/05/2008-12:16raprd01:13
04/05/2008-12:16::18
04/05/2008-12:16::18
#Check the Availability
04/05/2008-12:32ra:453
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
Reply With Quote
  #4 (permalink)  
Old 05-22-2008
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 104
Do this:

Code:
export FROM_DATE="04/05/2008"
export TO_DATE="06/05/2008"
Reply With Quote
  #5 (permalink)  
Old 05-23-2008
Registered User
 

Join Date: May 2008
Posts: 6
passing variable from bash to perl from bash script

Hi rikxik/Yogesh,
Cool Man , it is working with "export" cmd.
Thanks guys, you guys rocks.

Thanks a ton.
Arsidh
Reply With Quote
  #6 (permalink)  
Old 06-02-2008
Registered User
 

Join Date: May 2008
Posts: 6
Arrow passing variable from bash to perl from bash script

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 .
Reply With Quote
  #7 (permalink)  
Old 06-02-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,111
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.
Reply With Quote
Google UNIX.COM
Reply

Tags
export, perl script

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0