Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: creating Shell Script using Perl

by vinoth.ree (Monsignor)
on Sep 06, 2017 at 06:04 UTC ( #1198739=note: print w/replies, xml ) Need Help??


in reply to creating Shell Script using Perl

Hi pratikmonu

Look at the below code I have just changed the print statement with 'single quote' to stop the variable interpolation to use the variable as it is. In your code perl looks for scalar variable $FILE and $STRING.

use strict; use warnings; sub create_db_install_val(){ my $File_name=$ENV{'HOME'}."/DB_INSTALL_VALIDATION.sh"; print "\n Shell name to validate DB Installation Completion is $File_n +ame\n"; open (FILE,">$File_name") or die "cannot open $File_name file"; print FILE "#!/bin/sh\n"; print FILE "FILE=\"/scratch/pratranj/DB_11.2.0.1.0/config/setup.log\"\ +n"; print FILE "STRING=\"Completed creating database instance\"\n"; print FILE "EXIT=1\n"; print FILE "while : ;do\n"; print FILE ' [[ -f "$FILE" ]] && grep -q "$STRING" "$FILE" && echo +"DB Installation is completed" && break',"\n"; print FILE "sleep 5\n"; print FILE "done\n"; close(FILE); }
Updated the code after Re^2: creating Shell Script using Perl

All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: creating Shell Script using Perl
by AnomalousMonk (Bishop) on Sep 06, 2017 at 06:54 UTC
    print FILE '    [[ -f "$FILE" ]] && grep ... && break\n';

    This gives you a literal  \n (backslash-n) at the end | embedded in the output file. See this for a better (IMHO) approach.


    Give a man a fish:  <%-{-{-{-<

      Oh! Sorry about that, didn't noticed it, I just concentrated on getting those variable into the shell script.


      All is well. I learn by answering your questions...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1198739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2020-09-19 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?