Using output of perl script in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using output of perl script in shell
# 1  
Old 01-06-2010
Using output of perl script in shell

Hi,

I have a perl script which prints the epoch value of given date.

I want to use its output in a shell script.Can someone suggest me how to do it.

Thanks and Regards
Jyothi
jyothi_wipro
# 2  
Old 01-06-2010
sh/ksh/bash

a=`perl perlscript.pl`
# 3  
Old 01-06-2010
Hi,

My perl script is as below:

Code:
#!/usr/bin/perl -w
use Time::Local ;
$bsec=04;
$bmin=41;
$bhours=01;
$bday=14;
$bmonth=7;
$year=109;
$esec=33;
$emin=9;
$ehours=14;
$eday=17;
$emonth=8;
#
$Beg_time = (timelocal($bsec,$bmin,$bhours,$bday,$bmonth,$year) * 1000);
print "Epoch Beg Value: $Beg_time\n";
$End_time = (timelocal($esec,$emin,$ehours,$eday,$emonth,$year) * 1000);
print "Epoch End Value: $End_time\n";

And my shell script is as below:

Code:
echo "use db1" > query
#echo "select count(*) from file_info where beg_time>=1250194264000 and end_time<=1253176773000;" >> query
#echo "exit" >> query
./mysql --skip-column-names --socket=/tmp/mysql.sock < query >> info_id


My Perl script gives me the output of date in milliseconds.
Now I want that output to be used in shell script ie in the query taking beg_time and end_time.

Any suggestions how to do that?
Other doubt is: Is there any way that i can include the perl script into shell script so that i can directly run one script to get what i want rather running both separately and using the output of perl in shell?
jyothi_wipro
# 4  
Old 01-06-2010
something like:

Code:
bval=$(perl perlscript.pl | awk -F": " '/Epoch Beg Value/{print $2}')
eval=$(perl perlscript.pl | awk -F": " '/Epoch End Value/{print $2}')


beg_time>=$bval and end_time<=$eval

# 5  
Old 01-06-2010
Hi Anchal,
Thanks a lot.It worked out.

Regards,
Jyothi
jyothi_wipro
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Script output

Hi All, I have an expect script that I would like a perl script to call in order to login to a node and run in a single command. The command being running is a log of events so has lots of data that will be output. I would like to output that data to a file. Would anyone be kind enought... (1 Reply)
Discussion started by: mutley2202
1 Replies

2. Shell Programming and Scripting

Oneliner ---split string to character by piping shell output to perl

Hello, I was trying to split a string to characters by perl oneliner. echo "The quick brown fox jumps over the lazy dog" | perl -e 'split // ' But did not work as with bash script pipe: echo "The quick brown fox jumps over the lazy dog" | fold -w1 | sort | uniq -ic 8 1 T 1... (6 Replies)
Discussion started by: yifangt
6 Replies

3. Shell Programming and Scripting

[Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :] By default, the output of TSM's console has no timestamping, making it hard to sort through accurately. This puts my console into... (5 Replies)
Discussion started by: Vryali
5 Replies

4. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Shell Programming and Scripting

Perl CGI. no output until backend script is done

It is a basic Perl CGI question, I want to print out "Processing ... " while backend script /script/wait.pl is still running. But acctually, nothing appeared in browser untill /script/wait.pl finished. print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print... (4 Replies)
Discussion started by: honglus
4 Replies

6. Shell Programming and Scripting

Assign perl output to ksh shell variable

Hello, I am writing a ksh script on an AIX system. I need to get the date and time from a file into a variable. I found the following perl script from another post on this site and modified it slightly to output the format I need: perl -e '@d=localtime ((stat(shift)));... (4 Replies)
Discussion started by: swimp
4 Replies

7. Shell Programming and Scripting

how to get split output of a file, using perl script

Hi, I have file: data.log.1 ### s1 main.build.3495 main.build.199 main.build.3408 ###s2 main.build.3495 main.build.3408 main.build.199 I want to read this file and store in two arrays in Perl. I have following command, which is working fine on command prompt. perl -n -e... (1 Reply)
Discussion started by: ashvini
1 Replies

8. Shell Programming and Scripting

wrong output in perl script

Hi, Here is my piece of code-- #!/usr/bin/perl my $Time_Stamp ; my $User_Name; my $Success; my $Failure; my $ErrorCode; my $ErrorMsg; my $logDir = $ARGV; my $logPrefix = $ARGV; die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix; die "Log dir $logDir doesn't... (2 Replies)
Discussion started by: namishtiwari
2 Replies

9. Shell Programming and Scripting

error in output of perl script

Hi, This is my piece of code. my $logFile = $ARGV; die "usage: $0 <logFile>" unless $logFile; die "Logfile $logFile doesn't exist" unless -f "$logFile"; open(my $log, "<", $logFile) or die "Can't open $logFile for reading."; print "Processing file $logFile...\n"; #my $authenticates... (2 Replies)
Discussion started by: namishtiwari
2 Replies

10. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies
Login or Register to Ask a Question