- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 07:45 AM
03-31-2005 07:45 AM
I need to get this done in ksh script. I have the
following output from lpstat -o (we are trying to
capture the jobs which are in the print queue for 7
days or more). lpstat -o output is attached. Please
help.
Thanks
Brian.
Solved! Go to Solution.
- Tags:
- lpstat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 07:46 AM
03-31-2005 07:46 AM
Re: ksh script help
We are trying to capture the jobs which are 7 days or more in the queue and email them to admins.
Thanks
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 08:07 AM
03-31-2005 08:07 AM
Re: ksh script help
#!/usr/bin/ksh
7day_back=`perl -e '$sevenday = localtime(time-24*60*60),print "$sevenday\n"'|awk '{print $2, $3}'`
lpstat -o | grep "${7day_bak}"
Anil
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 08:19 AM
03-31-2005 08:19 AM
Re: ksh script help
#!/bin/ksh
export HNAME=`/bin/hostname`
cd /var/spool/lp/request
for i in `find . -type f -name "cA*${HNAME}" -mtime +7`
do
printer=`echo $i | cut -f 2 -d"/"`
job=`echo $i | cut -f 3 -d"/"| sed -e "s/^cA//" -e "s/$HNAME//"`
echo Print Job $job on printer $printer is older than 7 days
done | mailx -s "OLD PRINT JOBS" admin@urcompany.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 08:27 AM
03-31-2005 08:27 AM
Re: ksh script help
Thanks
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 10:19 AM
03-31-2005 10:19 AM
SolutionThe script I wrote doesn't use your output -
it uses the fact that those files will reside in the output queue directories to create a simple find command to do the work.
But, it should be a simple thing to get the one Anil posted to work just pipe it to mailx command like I have at the end of the command I posted above.
- Tags:
- mailx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 01:49 PM
03-31-2005 01:49 PM
Re: ksh script help
There was a typo in the ksh script. I changed that but i still get the broken pipe error. Wonder what the issue would be?
Thanks
Brian.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 04:17 PM
03-31-2005 04:17 PM
Re: ksh script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2005 11:56 PM
03-31-2005 11:56 PM
Re: ksh script help
This is what i get when i execute the script
$./print.sh
./print.sh[4]: 7day_back=Mar: not found
./print.sh[6]: "${7day_back}": bad substitution
$Broken Pipe
Please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 12:26 AM
04-01-2005 12:26 AM
Re: ksh script help
SevenDaysBack=`perl -e '$sevenday = localtime(time-(7*24*60*60));print "$sevenday\n"'|awk '{print $2, $3}'`
and of course 7 days back is time - (7 * 24 * 60 *60)
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 12:27 AM
04-01-2005 12:27 AM
Re: ksh script help
Change 7days_back to days_back or sevendays_back
Good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 02:22 AM
04-01-2005 02:22 AM
Re: ksh script help
I am getting null string for $sevenday $2 and $3 these are also null. please help.
Thanks
brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 02:50 AM
04-01-2005 02:50 AM
Re: ksh script help
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 03:17 AM
04-01-2005 03:17 AM
Re: ksh script help
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 05:09 AM
04-01-2005 05:09 AM
Re: ksh script help
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 05:29 AM
04-01-2005 05:29 AM
Re: ksh script help
Thanks a ton
Brian