Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Script Automation

by OkieUnix (Initiate)
on Aug 14, 2007 at 07:06 UTC ( [id://632409]=perlquestion: print w/replies, xml ) Need Help??

OkieUnix has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write an perl code that will create a shell script be it bash, bourne, ksh or what ever it be. I'm having to read a spreadsheet and I'm using some Win32 OLE modules along with Write and Parse Excel modules. So I have that part down ok. But I'm trying to figure how to create or embed a template within the script that will write out the shell script I require. Let's say the spreadsheet contained /var/log as a field that the program read. Then I wanted the perl script to create a simple shell script. That do this: #!/bin/sh # df -k /var/log # end of script. Something like that. Have you got any suggestions?

Replies are listed 'Best First'.
Re: Script Automation
by moritz (Cardinal) on Aug 14, 2007 at 07:36 UTC
    For such a short script I wouldn't bother using a template, you can just use two print statements to generate such a shell script.

    For longer/complexer scripts you could use Text::Template or one of the many other templating systems on cpan.

      Thanks, I will give that try as my scripts will be fairly long. I wanted a way to replicate the process.
Re: Script Automation
by Zaxo (Archbishop) on Aug 14, 2007 at 07:57 UTC

    Template Toolkit is my favorite template engine, it should do what you want.

    After Compline,
    Zaxo

Re: Script Automation
by cdarke (Prior) on Aug 14, 2007 at 07:48 UTC
    I'm not sure what you are asking for. Writing out a script from Perl is just like writing any other text file, except for things like execute access.
    The code you give:
    #!/bin/sh # df -k /var/log # end of script
    will not work - unlike Perl, shells take a newline (or a ;) as a statement terminator - that line will be seen as one #! line:
    #!/bin/sh # df -k /var/log # end of script
    is just three lines of comments, so you should loose the second #.
    Ever considered using Perl instead of the shell?
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Script Automation
by andreas1234567 (Vicar) on Aug 14, 2007 at 09:11 UTC
    There is an EYWTKATSADDTA (1) article over at apache.org which compares different templating systems.

    (1) (Everything you wanted to know about templating systems and didn't dare to ask)

    --
    Andreas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://632409]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found