- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help with script
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
Discussions
Discussions
Discussions
Forums
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
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
тАО05-31-2001 03:42 AM
тАО05-31-2001 03:42 AM
I am trying to write a script that will run every 1/2 hour through cron that will check to see if someone submits a print job to a specific printer. If it finds a print job, then it will send me an email, otherwise, it would just go away and sleep until the next time.
This is what I have so far and the part I have a problem with is the if command. If it finds a print job going to , then send email.
#!/usr/bin/ksh
#
RETVAL=0
PATH=$PATH:/usr/sam/lbin:/usr/sam/bin:/usr/bin:/usr/sbin:/sbin;export PATH
#
echo "Subject: Check printer user"`date` >>/tmp/echkmail.$$
echo "This routine is about to check the EW Cheque printer for : " >>/tmp/echkmail.$$
echo "Users that are not authorized to use it.!! " >>/tmp/echkmail.$$
echo " " >> /tmp/echkmail.$$
lpstat -o|grep echeck1 >> /tmp/echeckyes
grep echeck1 /tmp/echeckyes
if [ $RETVAL -ne 0 ]
then
sendmail nickd < /tmp/echeckyes
else
echo "No echeck1 print files found" >> /tmp/echkmail.$$
fi
#
# mail out results
#
sendmail nickd < /tmp/echkmail.$$
sendmail nickd < /tmp/echeckyes.$$
#rm /tmp/echkmail*
Suggestions are always appreciated,
ND
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2001 04:06 AM
тАО05-31-2001 04:06 AM
Re: Help with script
i would replace the part:
lpstat -o|grep echeck1 >> /tmp/echeckyes
grep echeck1 /tmp/echeckyes
if [ $RETVAL -ne 0 ]
with:
if [ $(lpstat -t | grep -c echeck1-) ]
This will do the following. In the lpstat if there is a job for the printer echeck1 it will have the jobid echeck1-12345 or so. With the grep command you look for those jobid's and count them (-c). If there is no job the result will be 0 or false. If there is one or more job in the queue the result will be 1 or higher which means true.
Hope this helps. Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2001 04:14 AM
тАО05-31-2001 04:14 AM
SolutionThe problem is that your not really testing the return value from the 'grep' of the 'lpstat' call. Try something like this:
...
lpstat -o|grep echeck1 > /dev/null
if [ $? -eq 1 ]
then
echo "nothing found"
else
echo "found a match"
fi
The idea of redirecting the output to /dev/null is simply that you don't need anything more than the true/false result which you test as above.
...JRF...
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2001 04:21 AM
тАО05-31-2001 04:21 AM
Re: Help with script
if lpstat -o | grep -q echeck1
then
echo "nothing found"
else
echo "found a match"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2001 05:46 AM
тАО05-31-2001 05:46 AM
Re: Help with script
grep printername /var/adm/lp/log
It shows all past print jobs, with usernames, dates and times, like this:
xplr-2229 xdk1 xplr May 31 09:28
Fred