Nagios to prosecute hard drive health status

Source: Internet
Author: User
Tags egrep

Simple Script implementation:

#!/bin/bashdevices="SDA SDB"#有几块硬盘就写几块Smartctl=/usr/sbin/Smartctlsmart_tmp_file="/opt/nagios/tmp/.smart" forDEVinch$DEVICES DoREL=`sudo$SMARTCTL-H/dev/$DEV |Egrep-I.'(health status|test result)'|awk-F:'{print $}'|awk '{print $}'`        Echo-N"${dev}:${rel}">>$SMART _tmp_file Done>>/tmp/eeee.log2>&1Egrep-I.'(Failed|err)'$SMART _tmp_fileretval=$?if[$RETVAL-ne0 ] Then        Echo "OK-' cat $SMART _tmp_file '"        RM-F $SMART _tmp_file exit0Else        Echo "CRITICAL-' cat $SMART _tmp_file '"         RM-F $SMART _tmp_file exit2fi

The script is simple, but it's not easy to execute, the root user executes the script, tests everything okay, but runs the problem with Nagios users.
First, the Nagios user does not have permission to execute the SMARTCTL command: Modify the Soduers file

Executive Visudo

Under Root all= (All), add the following

Nagios all= (Root) Nopasswd:/usr/sbin/smartctl *

# #NOPASSWD可以在脚本执行实不用输入密码

It's just not going to work, and when you do it with Nagios users will get an error:Sudo:sorry, you must has a TTY to run sudo

Further changes:

Or execute the visudo command (Of course execute vi/etc/sudoers is also perfectly possible)

Find Defaults requiretty, front Plus ' # ' comment off all OK!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.