LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I need help writing script to monitor the hard disk space (https://www.linuxquestions.org/questions/linux-newbie-8/i-need-help-writing-script-to-monitor-the-hard-disk-space-667104/)

xmdms 09-04-2008 10:39 AM

Quote:

Originally Posted by vikas027 (Post 3268794)
For using ssh without password follow these steps:

1) ssh-keygen -t dsa (or rsa)
2) press enter until prompt comes again.
3) two files will be in $HOME/.ssh directory.
id_rsa
id_rsa.pub
4) now simply copy the content of this file, to the $HOME/.ssh/authorized_keys file of the other server.

Thank you!!

How would I change the syntax of my script by adding a "From", to tell it from a legitimate e-mail account??

Example:
From: real.user@yahoo.comTo: xmdms@yahoo.com
Subject: Disk Space is low

Your disk space on ______ please check!!

vikas027 09-05-2008 03:15 AM

Quote:

Originally Posted by xmdms (Post 3269448)
Thank you!!

How would I change the syntax of my script by adding a "From", to tell it from a legitimate e-mail account??

Example:
From: real.user@yahoo.comTo: xmdms@yahoo.com
Subject: Disk Space is low

Your disk space on ______ please check!!

I could not understand you, you want to inform the user about the disk utilization ??

xmdms 09-05-2008 07:27 AM

Quote:

Originally Posted by vikas027 (Post 3270327)
I could not understand you, you want to inform the user about the disk utilization ??

As you can see from the script below. I would like to know what's the command lines for adding "From" rather than have it coming Root as the user sending the e-mail message.

Example:

RECIPENTS="xmdms@yahoo.com"
typeset -i error="92"
if [ -e \tmp\space.out ]; then
rm \tmp\space.out
fi
for disk in `mount | egrep '^/dev' | egrep -iv 'cdrom|proc|sys|pts' |awk '{print $3}'`
do
typeset -i diskUsage=`df -h $disk|cut -c40-42|grep -i [^a-z]`
if [ "$diskUsage" -ge "$error" ]; then
echo "Disk usage $disk exceeded the threshold of $diskUsage%" >> \tmp\space.txt
fi
done
if [ -e \tmp\space.out ]; then
message=`cat \tmp\space.out`
fi
if [ ${#message} -gt 0 ]; then
cat \tmp\space.out | mail -s "Disk Usage Report for: $HOSTNAME" $RECIPENTS
fi

CRC123 09-05-2008 08:50 AM

mail -r you@domain.com -s "Disk Usage Report for: $HOSTNAME" $RECIPENTS

xmdms 09-05-2008 10:11 AM

Quote:

Originally Posted by CRC123 (Post 3270564)
mail -r you@domain.com -s "Disk Usage Report for: $HOSTNAME" $RECIPENTS

'-r' is not an option for mail. I get an error when running with an '-r' option. The man page doesn't display an option for -r either.

Please advice.

Thanks!!

mail: invalid option -- r
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...
[- sendmail-options ...]
mail [-iInNv] -f [name]
mail [-iInNv] [-u user]

CRC123 09-05-2008 11:00 AM

Hmm, mine works, but my 'mail' command is a symbolic link to the 'mailx' program. Do you have a 'mailx' program on your computer?

xmdms 09-05-2008 11:13 AM

Quote:

Originally Posted by CRC123 (Post 3270665)
Hmm, mine works, but my 'mail' command is a symbolic link to the 'mailx' program. Do you have a 'mailx' program on your computer?

That's the problem. I am running RHAS 4.0 - You're probably running older version of Redhat or something else. I do know that Unix also used mailx, but not here.

I wonder.....

CRC123 09-05-2008 12:54 PM

Im on opensuse 11.0, but in my man pages, it says that if you set the 'from' or 'FROM' variable, it should use that as the "from" address of mail addresses, so try this:

Code:

export from="myemail@blah.com"
or
export FROM="myemail@blah.com"

I hope that helps, otherwise, I dunno.

xmdms 09-05-2008 02:14 PM

Quote:

Originally Posted by CRC123 (Post 3270769)
Im on opensuse 11.0, but in my man pages, it says that if you set the 'from' or 'FROM' variable, it should use that as the "from" address of mail addresses, so try this:

Code:

export from="myemail@blah.com"
or
export FROM="myemail@blah.com"

I hope that helps, otherwise, I dunno.

Came back as nothing for both commands. My man page displayed,

OPTIONS
The mailx utility shall conform to the Base Definitions volume of
IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.

The following options shall be supported. (Only the -s subject option
shall be required on all systems. The other options are required only
on systems supporting the User Portability Utilities option.)

-e Test for the presence of mail in the system mailbox. The mailx
utility shall write nothing and exit with a successful return
code if there is mail to read.

-f Read messages from the file named by the file operand instead
of the system mailbox. (See also folder.) If no file operand is
specified, read messages from mbox instead of the system mail-
box.

-F Record the message in a file named after the first recipient.
The name is the login-name portion of the address found first
on the To: line in the mail header. Overrides the record vari-
-H Write a header summary only.

-i Ignore interrupts. (See also ignore.)

-n Do not initialize from the system default start-up file. See
the EXTENDED DESCRIPTION section.

-N Do not write an initial header summary.

-s subject
Set the Subject header field to subject. All characters in the
subject string shall appear in the delivered message. The
results are unspecified if subject is longer than {LINE_MAX} -
10 bytes or contains a <newline>.

able, if set (see Internal Variables in mailx .)
-u user
Read the system mailbox of the login name user. This shall only
be successful if the invoking user has the appropriate privi-
leges to read the system mailbox of that user.


I guess, I will just have to setup the relay to our Windows Mail Server.


All times are GMT -5. The time now is 07:32 AM.