[Chicago-talk] printing a hash value that has shell code in it.

Steven Lembark lembark at wrkhors.com
Fri Dec 5 17:41:57 CST 2003



-- "Dooley, Michael" <Dooley.Michael at con-way.com>

> open (DFH_FILE, "/var/adm/scripts/dfh") or die "Can not read DFH file
> ($!)"; 	foreach (<DFH_FILE>) {
> 		chomp;
> 		($dfhtype, $dfh) = split(/=/, $_);
> 		$dfhtype=lc("$dfhtype");
> 		$dfhhash{$dfhtype}=$dfh;
> 	}
> close DFH_FILE;
>
> foreach (values (%dfhhash)) {
> print $_,"\n";
> }
> -----
> what if each line in DFH_FILE look like this. Anyone have any ideas how I
> can convert the date portion to a legitamit date.

> Q107945="DFH1  CW_OMS         4165909998     `date
> +%Y%m%d%H%M%S%Y%m%d%H%M%S` q107945     01"
> Q166204="DFH|1|q166|q190|`date +%Y%m%d`|`date +%H%M%S`|`date
> +%Y%m%d%H%M%S`|q166204i|0|1"
> ACCESSDBTXT="DFH,1,q100,CW_TMS,`date +%Y%m%d`,`date +%H%M%S`,`date
> +%Y%m%d%H%M%S`,q100204i,0,1"
> OMSARFIN="DFH   1       CW_OMS  CW_FIN  `date +%Y%m%d`  `date +%H%M%S`
> `date +%Y%m%d%H%M%S`    AR_OUT  0       1"

Where are the dates in this input?

One way might be:

	sub get_a_date
	{
		local $/;

		my $input = <ARGV>;

		# formatz is extraneous for exececution, nice for debugging.

		my @formatz = $input =~ m{\+([\w%]+)}g;

		chomp (my @output = map { qx(date +'$_') } @formatz);

		@output
	}

	my @date_stringz = get_a_date;

Point is to extract all of the +DATE_FORMAT_STRINGS and then
feed them through the local copy of date.

Odds are that Date::Format (mucho faster than Date::Manip)
will handle the same format strings since they both use the
time2str C subs:

	chomp ( my @output = map { time2str $_, time } @formatz );

may do it with less overhead.



--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 888 359 3508



More information about the Chicago-talk mailing list