1753779 Members
7379 Online
108799 Solutions
New Discussion юеВ

Re: ksh script help

 
SOLVED
Go to solution
Henk Pilon
Trusted Contributor

Re: ksh script help

Just don't start the name of a variable with a digit. ksh expects that to be a standard variable passed to the script at the commandline. ($0 - $9)
Change 7days_back to days_back or sevendays_back

Good luck
brian_31
Super Advisor

Re: ksh script help

anil/all:

I am getting null string for $sevenday $2 and $3 these are also null. please help.

Thanks

brian
harry d brown jr
Honored Contributor

Re: ksh script help

What do you get when you run this:

perl -e '$sevenday = localtime(time-(7*24*60*60));print "$sevenday\n"'|awk '{print $2, $3}'

or this:

perl -e '$sevenday = localtime(time-(7*24*60*60));print "$sevenday\n"'

live free or die
harry d brown jr
Live Free or Die
Hein van den Heuvel
Honored Contributor

Re: ksh script help

Hmmm,

that $sevendays thing works fine for me:

> ksh
$ SevenDaysBack=`perl -e '$sevenday = localtime(time-(7*24*60*60));print "$seven
day\n"'|awk '{print $2, $3}'`

$ echo $SevenDaysBack
Mar 25


fwiw, Personally it rubs me the wrong way to follow perl with awk when a trivial perl solution is available. For example:

$ perl -e '$_ = localtime(time-(7*24*60*60)); @old=split; print "$old[1] $old[2]
\n"'
Mar 25
$

To carry that theme forward, why not compare the dates in perl? Now the 'Mar 31' style date is hard to compare. So first convert it to seconds. Then compare with current time in seconds minus cutoff time. I don't know how to have perl do month-string to month-number nicely (Language independend, so I cheated and hardcoded a month table:

Start of a solution:

---- find_old.p ----
use Time::Local;
$year = (localtime)[5];
while (<>){
if (/(\w+)\s+(\d+)\s+(\d+):(\d+)$/) {
$mon = index("JanFebMarAprMayJunJulAugSepOctNovDec",$1)/3;
$t = timelocal(0,$4,$3,$2,$mon,$year);
print if ($t < time - (7*24*60*60))
}
}

---- sample output for slightly editted input sample ---

perl find_old.p lpstat.txt
brflora-295 aflorad1@essdbdu31 4330 Mar 21 19:30
brflora-298 aflorad1@essdbdu31 5444 Feb 2 19:30


It should be straight forwards to just print names, numbers, or email from that perl script.

Good luck,
Hein.
Rory R Hammond
Trusted Contributor

Re: ksh script help

Brian,

I know that you are focused on the lpstat command.
I approached the problem differently
cd /var/spool/lp/request
find . -type file -mtime -7 -print
and then process that list.

good luck
Rory
There are a 100 ways to do things and 97 of them are right
brian_31
Super Advisor

Re: ksh script help

Thanks Harry, Hein. It works. What a Forum this is!!!! Unbeleivable.

Thanks a ton

Brian