Sponsored Content
Top Forums Shell Programming and Scripting convert perl code to shell script Post 302417241 by x34 on Thursday 29th of April 2010 02:31:25 AM
Old 04-29-2010
convert perl code to shell script

This is about how to Monitoring folder for new files using shell script

im doing a project using smsserver tools 3. i have used a perl script
to handle incoming messages. the content of each message must be
directed to a java program. this program generates the answer to reply
to the user .so i need to call the java program from the perl code.
this is my perl code


Code:
//******************************************************************************************************************************************

#!/usr/bin/perl -w

use strict;
use File::Monitor;
use File::Monitor::Object;


my $number = '';
my $msgFrom = '';

my $outgoing = "/home/T/Documents/run/outgoing/";
my $extract ="/home/T/Documents/run/extract part/";

my $temp = '/var/spool/sms/incoming';

my $monitor = File::Monitor->new();
my $newline = 0;

$monitor->watch( {
        name        => "$temp",
        recurse     => 1,
        callback    => \&Test,
    } );

$monitor->scan;

for (my $i=0; $i < 100; $i++)
{
      my @changes = $monitor->scan;
      sleep 5;
}

sub Test
{
      my ($name, $event, $change) = @_;

      my @adds = $change->files_created;
      my @dels = $change->files_deleted;

      if(@adds){

                print "Added: ".join("\nAdded: ", $adds[0])."\n"; # if  @adds;
                my $filename = $adds[0];
                open (INFILE, $filename); # if @adds;
                 while (my $line = <INFILE>) {
                chomp $line;

                         $line = lc($line);

                         if ($newline == 1) {
                                  $msgFrom = $msgFrom.$line;
                                printf "*************".$msgFrom;
                        }

                         if ($line =~ /^from: (.*)/) {
                                  $number = $1;
                         } elsif (length($line) == 0) {
                          $newline = 1;
                 }
    }
                close INFILE;


                open(OUTFILE1 , ">".$number.".txt");

                print OUTFILE1 ("hi gfdg");
                close OUTFILE1;

                open(OUTFILE, ">".$outgoing."sms".$number."-".int(rand(100000)));
#open for write, overwrite
                print OUTFILE ("To: ",$number); #write text without  newline
                print OUTFILE "\n\n";
                print OUTFILE join(',','hi is this working '); #write  text
                print OUTFILE "\n"; #write newline
                close OUTFILE;
        }
}

//******************************************************************************************************************************************

can anyone help me to write this perl code in shell script ?

or is there a way to call java programe inside perl code?

Last edited by pludi; 04-29-2010 at 10:06 AM.. Reason: code tags, please..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

convert the below perl sript to shell script

perl script: my $logdir = '/smp/dyn/logfiles/fsm/mp/mp'; $logdir = $logdir ."/mp${toDate}*"; i tried to make it..as below .. but not working .. date +%m%d%y logdir = /smp/dyn/logfiles/fsm/mp/mp logdir=$logdir/mp"$date" but it was not working..... can someone please help me out in... (1 Reply)
Discussion started by: mail2sant
1 Replies

2. Shell Programming and Scripting

How to run perl code within a shell script...?

Hi, I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me Thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies

3. Shell Programming and Scripting

convert PERL script to SHELL script

Hi all experts, I am new to Unix. Could you please help me to convert the following PERL script to SHELL? I will appreciate. #!/bin/sh use strict; use warnings; my $robot_num = 0; my %rob_tapes; foreach (`/usr/openv/volmgr/bin/vmquery -l -rn $robot_num`) { $rob_tapes{(split)} = 1; }... (6 Replies)
Discussion started by: ma466
6 Replies

4. Shell Programming and Scripting

Shell/Perl script to convert to Capitalize case

I need a shell script which will convert the given string within a <title> tag to Capitalize case. E.g "<title>hi man: check this out</title>" to "<title>Hi Man: Check This Out</title>" (11 Replies)
Discussion started by: parshant_bvcoe
11 Replies

5. Shell Programming and Scripting

Help: how to convert perl script to shell script

bash$ mdb-schema x.mdb | perl -wpe 's%^DROP TABLE %DROP TABLE IF EXISTS %i; s%(Memo/Hyperlink|DateTime( \(Short\))?)%TEXT%i; s%(Boolean|Byte|Byte|Numeric|Replication ID|(\w+ )?Integer)%INTEGER%i; s%(BINARY|OLE|Unknown (+)?)%BLOB%i; s%\s*\(\d+\)\s*(,?*)$%${1}%;' | sqlite3 x.db ... (1 Reply)
Discussion started by: jackpapa
1 Replies

6. 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

7. Shell Programming and Scripting

Convert shell script to Perl

Hello,,I have a very small script that contains these lines; and it works perfectly; however I need to use Perl now as I will need to feel variables from a MySQL table into this; to it would be nice to start by converting this first... find / -perm 777 \( -type f -o -type d \) -exec ls -lid {}... (1 Reply)
Discussion started by: gvolpini
1 Replies

8. Shell Programming and Scripting

perl to shell convert

#!/usr/bin/perl #************************************************************** # # PERL SCRIPT # This script restarts the Application # # ##************************************************************** $ENV{'IFS'} = ' '; #open(STDERR,">&STDOUT"); #select... (2 Replies)
Discussion started by: srikoundinya
2 Replies

9. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies

10. Shell Programming and Scripting

Need shell script version of below perl code

We are using AIX version 7100-03-05-1524 Please provide shell script version (bash or ksh) of below perl code,since we need to have line breaks in huge XML files #!/usr/bin/perl # # Purpose: Read an XML file and indent it for ease of reading # Author: RedGrittyBrick 2011. # Licence:... (11 Replies)
Discussion started by: vishwanath001
11 Replies
exit(1) 							   User Commands							   exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 04:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy