Finally i ran env command n copied all of them in the beginning of my script. Still it throwing empty mails to root whenever cron runs the script.
#!/bin/bash
[[ "`/usr/bin/tty`" == "not a tty" ]] && . ~/.bash_profile
HOSTNAME=qmail.com
TERM=xterm
SHELL=/bin/bash
SSH_TTY=/dev/pts/1
USER=root
KDEDIR=/usr
MAIL=/var/spool/mail/root
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/ bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
INPUTRC=/etc/inputrc
PWD=/root
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=::ffff:192.168.0.218 4676 ::ffff:192.168.0.222 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
TERM=linux
export TERM
clear
touch mailcontent.txt
flag1=0
flag=0 #initialze a flag
sleep 1
if [ "$(nmap -P0 -p25 1.2.3.4 | grep open)" ] #port check
then
flag1=0 #dummy
else
flag=1 #set flag
echo SMTP seems not open in 1.2.3.4, Please check \n >> mailcontent.txt #update error file
fi
sleep 1
if [ "$(nmap -P0 -p110 1.2.3.4 | grep open)" ]
then
flag1=0
else
echo POP seems not open in 1.2.3.4, Please check \n >> mailcontent.txt
flag=1
fi
.
.
.
.
like this many servers
.
.
.
.
.
.
if [ $flag -eq 1 ] ;
then
mail -s "First level warning"
root@qmail.com < mailcontent.txt
else
flag1=0
fi
rm mailcontent.txt
This is my script. Please tell me why its throwing empty mails to root.....Please i am struggling for a long time.............