LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-19-2015, 04:57 AM   #1
pantdk
Member
 
Registered: Oct 2011
Location: New Delhi
Posts: 248
Blog Entries: 3

Rep: Reputation: 17
Shell Script to check the printer status not sending email


Hi All,

I am new for shell script i have prepared the script
& when i run the script manually
./printer_script.sh it will send me the list of disable printer
now when I set it on cron it didn't send any email but it cron is run in every two min it i have check the cron logs Please let me know where i have made a mistake

Mar 19 17:16:01 SERVERcrond[27771]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:18:01 SERVERcrond[1624]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:20:01 SERVERcrond[8044]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:22:01 SERVERcrond[14760]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:24:01 SERVERcrond[21080]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:26:01 SERVERcrond[27415]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:28:01 SERVERcrond[1286]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:30:01 SERVERcrond[7742]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:32:01 SERVERcrond[14428]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:34:01 SERVERcrond[20746]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:36:01 SERVERcrond[27115]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:38:01 SERVERcrond[987]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:40:01 SERVERcrond[7371]: (root) CMD (/home/pantd/printer_script.sh)
Mar 19 17:42:01 SERVERcrond[14135]: (root) CMD (/home/pantd/printer_script.sh)

cron entry
###check the printer status#######
*/2 * * * * /home/pantd/printer_script.sh



#!/bin/sh
#This script is designed to check the status of a printer
#if printer is disable it will send email to the DL to enable the printer
############# Variable
set -vx
dt=`uptime;date;uname -n`
DR=`lpstat -p |egrep -i "disabled|Enabled" > /home/pantd/printerstatus.txt`
SR=`cat /home/pantd/printerstatus.txt |grep -i "disabled" > /home/pantd/Printer_Disabled.txt`
if [ -z $SR ]
then
mutt -a /home/pantd/Printer_Disabled.txt -s "Printer is disabled Please check status & enabled it" unix@test.com -c admin@test.com < /dev/null
else
echo "printer is enabled" "$dt" > /home/pantd/printer_enable.txt
fi
[pantd@server ~]$
 
Old 03-19-2015, 05:22 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
For any commands you want to use, such as uptime, date, uname, lpstat, etc. etc. you may need to use the full path to the command instead of just the command name.
 
Old 03-19-2015, 03:51 PM   #3
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
Add after set -vx:

export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
 
Old 03-20-2015, 12:37 AM   #4
pantdk
Member
 
Registered: Oct 2011
Location: New Delhi
Posts: 248

Original Poster
Blog Entries: 3

Rep: Reputation: 17
Hi All

Thanks for the suggestion
I have RHEL4 so might be that's reason

i have made the modification but not able to succeed now i am checking with mail command & that send me the logs in print format but i am looking report in attachment in txt format


/bin/mail -s "Printer is disabled" unix@test.com < /home/pantd/Printer_Disabled.txt

i am trying mailx also but that doesn't work

mailx -s "Printer status" -a home/pantd/Printer_Disabled.txt unix@test.com< /dev/null

Last edited by pantdk; 03-20-2015 at 12:39 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check the existence of an email address in yahoo whitout sending jayram1989 Linux - Software 1 03-26-2014 06:12 AM
script to check host status and report email in certaion losses franklin.sucre Linux - Newbie 3 01-06-2013 04:29 PM
LXer: Ordered Aakash Tablet? Check Your Status Via Email LXer Syndicated Linux News 0 01-14-2012 06:20 AM
Need to write a shell script which will check the GUI login and retuen the status cod bhsk_08 Linux - General 2 10-14-2008 01:08 PM
Check Printer Status Debby Linux - General 5 02-08-2002 08:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration