Using Perl Inside KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Perl Inside KSH
# 1  
Old 09-25-2009
Using Perl Inside KSH

Hi there,

I am new to Perl and KSH. The system I am using picks up the KSH scripts and uses them in a batch job control system.

I am trying to set a variable from a perl command

Code:
#!/bin/ksh -eaxp
#*******************************************************************************
# Testing Program
#*******************************************************************************
#+
#job "TEST":U*


#-

$time='perl -e 'print localtime();''

I cannot figure out how to make KSH capture the output of Perl scripts. Anyone have any insight on this?

Thank you in advance, I know how annoying these questions can be.
# 2  
Old 09-25-2009
you need to use backticks (i.e. ` ,on the tilde key, most likely) around your perl command, not single quotes, and remove the $ when you set the var, like so:

Code:
time=`perl -e 'print localtime();'`

then you can ref the var with $ like in 'echo $time'
# 3  
Old 09-28-2009
My problem now is pass variables this way.

Code:
typeset -Z4 Var
Var=1234
rm -rf myfile
perl -e -'open (POSTSET, ">myfile");
print POSTSET $Var;
close (POSTSET);'

Perl never gets that variable $Var. How do I pass Perl the variable from KSH?

Thanks.

Last edited by Franklin52; 10-02-2009 at 04:36 AM.. Reason: Please use code tags!
# 4  
Old 09-28-2009
Code:
perl -e -'open (POSTSET, ">myfile");
print POSTSET $ARGV[0];
close (POSTSET);'  "$var"

Start with the above. You do know the shell can write to a file more efficiently than invoking perl like that?
# 5  
Old 09-28-2009
all shell variables are stored in the $ENV hash built in to perl.

to access:
Code:
perl -e -'open (POSTSET, ">myfile");
print POSTSET "$ENV{Var}"
close (POSTSET);'

That being said, unless this is just sample code, as Jim pointed out, perl does seem like overkill here.
# 6  
Old 10-01-2009
Hint:
Code:
#!/bin/env ksh
/bin/env perl run_my_perl_script_that_does_everything_and_forget_about_shell.pl


Last edited by Franklin52; 10-02-2009 at 04:37 AM.. Reason: adding code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

2. Shell Programming and Scripting

Return value inside isql to a shell variable in ksh

Hello, I have a shell script where I am doing an isql to select some records. the result i get from the select statement is directed to an output file. I want to assign the result to a Shell variable so that I can use the retrieved in another routine. e.g. "isql -U${USER} -P${PASSWD} -S${SERVER}... (1 Reply)
Discussion started by: RookieDev
1 Replies

3. Shell Programming and Scripting

Using Sed to do a substitution inside ksh

I'm trying to do an ls from inside of a ksh script. I loop through the results one line at a time and attempt to do a substitution using sed to convert YYYYMMDD from the older files into the newer files. Basically sometimes the ETL load runs over midnight and half the files are off by one day... (3 Replies)
Discussion started by: Calbrenar
3 Replies

4. Shell Programming and Scripting

KSH SHELL: problem calculation number of lines inside compressed file

Hi Gurus, I am working with a korn shell script to simplify some operations of calculation number of lines inside compressed file. The called function (inside a cycle) is the following: ######################################### # F.ne: CheckCount #########################################... (3 Replies)
Discussion started by: GERMANICO
3 Replies

5. Shell Programming and Scripting

How to call an sql script inside a while statement in KSH

Hi all, I'm trying to run an sql inside a loop which looks like this #!bin/ksh while IFS=, read var1 var2 do sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << EOF insert into ${TABLE} ( appt_date ) values ( '${var1 }' ); ... (6 Replies)
Discussion started by: ryukishin_17
6 Replies

6. Shell Programming and Scripting

Getting cntrl-c entered inside a ksh script

hi guys, my ksh script is calling another script. The other script expects user to press CNTR-C, and does not return to the prompt. in my script, I want to call the other script, but somehow don't want it to wait forever, I want to return to my script. e.g. script2.ksh outputs: "No... (2 Replies)
Discussion started by: JamesByars
2 Replies

7. Shell Programming and Scripting

Using telnet inside a ksh

Hello, i am trying to use telnet inside of a ksh script. i would like to do like the following: #!/bin/ksh ... user="user" hostname="hostname" telnet -l $user $hostname |& wait #end of the ksh and with this piece of code, i would like to telnet another machine, and let the user use... (4 Replies)
Discussion started by: Jidma
4 Replies

8. Shell Programming and Scripting

Exit statement ignored inside KSH function

Hi All, I have multiple functions in my script and I'm trying to capture stdout from some of them, but I also do some error checking in them (in the functions that output something to their stdout that needs capturing) and I need to be able to end the entire script with an error message. ... (2 Replies)
Discussion started by: gkubok
2 Replies

9. Shell Programming and Scripting

expr inside a ksh script Solaris

Hi; If I do something like this. dftotalsize=0;export dftotalsize;df -k | grep \/db001 | awk '{print $4}' | while read theinput \ ; do export $theinput; dftotalsize=`expr $dftotalsize + $theinput`; export dftotalsize; echo $dftotalsize; done ; echo `expr $dftotalsize \/ 1024 \/ 1024 "GB" Is... (4 Replies)
Discussion started by: myjess
4 Replies

10. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies
Login or Register to Ask a Question