#!/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; }
In reply to Re: Shell script to Perl
by FreeBeerReekingMonk
in thread Shell script to Perl
by ansh_1415
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |