[ale] Question about scripting...
Tim Watts
timtw at earthlink.net
Mon Aug 10 11:34:37 EDT 2009
Another way to mix bash & perl uses perl's -x option and __END__.
The nice thing here is you don't have to worry about quoting so much. See man
perlrun for more details.
#!/bin/bash
echo "This is from bash"
perl -x $0 "$@"
echo "back to bash"
exit 0;
#!perl
use English;
use strict;
print "This is from perl\n";
my $a;
foreach $a (@ARGV) {
print "arg: $a\n";
}
__END__
Be sure to exit in the bash portion before you hit #!perl or bash will start
complaining. __END__ is not strictly necessary if nothing follows it in the
file.
On Monday 10 August 2009 8:28:18 am Chuck Payne wrote:
> Sorry if this question seem a bit silly, but I am still very much a
> newbie when it come some to scripting.
>
> I want to write a shell script that does some scp of files, but I like
> to use both bash and perl. Could I do some thing this, how would I
> got about mixing shell, python, perl and other things with in a
> script.
>
> #!/bin/bash
>
> workdir=/tmp
> file="`hostname`.`date +%m%d%Y`.tgz"
>
> # Functions
>
> scpjvm () {
>
> #!/usr/bin/perl -w
>
> use Net::SFTP;
> use strict;
>
> my $host = "mars.myhost.com";
> my %args = (
> user => 'toor,
> password => '1234567',
> debug => 'true'
> );
>
> my $sftp = Net::SFTP->new($host, %args);
> $sftp->get("/tmp/'jvm.`hostname`.`date +%m%d%Y`.tgz'",
> "/home/ia/'jvm.`hostname`.`date +%m%d%Y`.tgz'");
>
>
> }
>
> # The work
>
> cd $workdir
>
> tar czvfpP $file /etc/httpd /opt/jboss/jboss/bin/
> /opt/jboss/jboss/server /usr/local/bin --exclude *log* --exclude
> *nohup*
>
> scpjvm
>
> rm $file
--
It is the final proof of God's omnipotence that he need not exist in order to
save us.
-- Peter De Vries
More information about the Ale
mailing list