in reply to Shell script to Perl

Reconstructed SHELL program:

#!/bin/sh TEMPFILE0=/home/h150371a/file.tmp TEMPFILE1=/home/h150371a/file1.tmp sudo /usr/openv/netbackup/bin/admincmd/bpimagelist -A -media -hoursago + 24 |sed ' s/\|/ /'|awk '{print $1}' > $TEMPFILE0 cat $TEMPFILE0 | while read Image do sudo /usr/openv/netbackup/bin/admincmd/nbemmcmd -listmedia -me +diaid $Image | grep -iE 'Media ID|Data Expiration' >> $TEMPFILE1 done if [ -s "$TEMPFILE1" ] then mailx -s "Daily" ishonbackup.nar@capgemini.com < $TEMPFILE1 fi rm $TEMPFILE1 -MP # rm $TEMPFILE0

The only way I see this becoming faster in perl is if you do not write the files to disk, at expense of more RAM usage during execution.

NetWallah already did a good job of presenting you sample code... except you would get multiple emails instead of a single one... might want to replace that.

maybe this (also untested)

my @MEDIA; for (qx<sudo /usr/openv/netbackup/bin/admincmd/bpimagelist -A -media - +hoursago 24>){ s/\|/ /; my ($Image) = split; for (qx<sudo /usr/openv/netbackup/bin/admincmd/nbemmcmd -listmedia - +mediaid $Image>){ next unless m/Media ID|Data Expiration/i; push @MEDIA, $_; } } if(@MEDIA){ open(FF, "|/usr/bin/mailx -s 'Daily' ishonbackup.nar\@capgemini.com" +) or die $!; for (@MEDIA){ print FF $_ . "\n"; } close FF; }

Replies are listed 'Best First'.
Re^2: Shell script to Perl
by FreeBeerReekingMonk (Deacon) on Mar 02, 2016 at 09:40 UTC
    If the mailx is not working, check if you are allowed to send email outside. Some mailservers only allow root to go outside the intranet domain (and normal users not).
    ls > ls.txt mailx -s "testemail" ishonbackup.nar@capgemini.com < ls.txt