We all know that /dev/null is the 'bit bucker' or the 'black hole' (nothing but a special file
that discards all data written to it)
Background:
We also know the standard streaming conventions: STDIN(0) STDOUT(1) and STDERR(2)
&>filename =
Redirect both stdout and stderr to file "filename."
2>&1
# Redirects stderr to stdout.
# Error messages get sent to same place as standard output.
Now lets analyze:
>/dev/null 2>&1"
: This means that standard output goes to /dev/null and
standard error(2) should get redirected to where your standard output
is going(in our case it is /dev/null)
&> /dev/null
: As explained above, redirect standard output(1) and standard error(2)
to /dev/null
So coders and SA's this is actaully same and dont get(urself) and try
make other confused with this please :P
More you can read here
-DEBA
Tuesday, March 22, 2011
Sunday, March 6, 2011
logsave
Sometime I feel it is still gonna take years to explore all the available commands to leverage for what they were made for. For ex. yesterday I came to know the existence of a command called 'logsave' which made so many of tasks real easy.
Logsave command is used to save the output of a commands in a log file.
Syntax: logsave
I used it in my below script -
#!/bin/bash
# SCRIPT NAME: PreHealthCheck.sh
# DESCRIPTION: It does a precheck of all our Servers servers on disk and connectivity
# AUTHOR: D E B A
# OWNER: Fundoo Team
#########################################################
ADMIN="debajitkataki@gmail.com"
ALERT=80
flag=0
rm -f /tmp/PreChkRprt.txt
rm -f /tmp/report.txt
tmpFileName=/tmp/PreChkRprt.txt
touch ${tmpFileName}
email__msg(){
MailSubject="Prod Build Precheck report"
SuccessMessage=" Please check the below sections for any precheck concern:\n\n"
sed -i '1i ---------------------------------------------------------' ${tmpFileName}
sed -i '2i Please check the below sections for any precheck concern:' ${tmpFileName}
sed -i '3i ---------------------------------------------------------' ${tmpFileName}
echo -e "\n\n Script Signature: `hostname`:${0}" >> ${tmpFileName}
mail -s "Alert: Prod Build Precheck report" $ADMIN < ${tmpFileName}
diskSpace(){
echo -e "\n\n ##### -- High disk utilization Report --#####\n" >> ${tmpFileName}
for i in `cat wslist.txt`
do
usepar=0
output=0
ssh -oConnectTimeout=5 -xq $i df -Ph > /tmp/df.out
output=`cat /tmp/df.out | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }'`
usepar=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ "$usepar" -ge 80 ]
then
echo " $i is running out of space \"$partition = $usepar% \" " >> ${tmpFileName}
flag=1
fi
done
}
connctivity_check(){
echo -e "\n\n ##### ---- Checking connectivity ----#####" >> ${tmpFileName}
echo -e "--------------------------------------------------------------" >> ${tmpFileName}
echo -e"\n"
for i in `cat wslist.txt`; do logsave -a /tmp/report.txt nc -v -w 1 -z $i 22 ; done
grep "Connection timed out" /tmp/report.txt >> ${tmpFileName}
echo -e "\n ....rest all connecting fine on port 22!!" >> ${tmpFileName}
}
diskSpace
connctivity_check
email__msg
Thanks/-
D E B U
Logsave command is used to save the output of a commands in a log file.
Syntax: logsave
I used it in my below script -
#!/bin/bash
# SCRIPT NAME: PreHealthCheck.sh
# DESCRIPTION: It does a precheck of all our Servers servers on disk and connectivity
# AUTHOR: D E B A
# OWNER: Fundoo Team
#########################################################
ADMIN="debajitkataki@gmail.com"
ALERT=80
flag=0
rm -f /tmp/PreChkRprt.txt
rm -f /tmp/report.txt
tmpFileName=/tmp/PreChkRprt.txt
touch ${tmpFileName}
email__msg(){
MailSubject="Prod Build Precheck report"
SuccessMessage=" Please check the below sections for any precheck concern:\n\n"
sed -i '1i ---------------------------------------------------------' ${tmpFileName}
sed -i '2i Please check the below sections for any precheck concern:' ${tmpFileName}
sed -i '3i ---------------------------------------------------------' ${tmpFileName}
echo -e "\n\n Script Signature: `hostname`:${0}" >> ${tmpFileName}
mail -s "Alert: Prod Build Precheck report" $ADMIN < ${tmpFileName}
diskSpace(){
echo -e "\n\n ##### -- High disk utilization Report --#####\n" >> ${tmpFileName}
for i in `cat wslist.txt`
do
usepar=0
output=0
ssh -oConnectTimeout=5 -xq $i df -Ph > /tmp/df.out
output=`cat /tmp/df.out | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }'`
usepar=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ "$usepar" -ge 80 ]
then
echo " $i is running out of space \"$partition = $usepar% \" " >> ${tmpFileName}
flag=1
fi
done
}
connctivity_check(){
echo -e "\n\n ##### ---- Checking connectivity ----#####" >> ${tmpFileName}
echo -e "--------------------------------------------------------------" >> ${tmpFileName}
echo -e"\n"
for i in `cat wslist.txt`; do logsave -a /tmp/report.txt nc -v -w 1 -z $i 22 ; done
grep "Connection timed out" /tmp/report.txt >> ${tmpFileName}
echo -e "\n ....rest all connecting fine on port 22!!" >> ${tmpFileName}
}
diskSpace
connctivity_check
email__msg
Thanks/-
D E B U
Subscribe to:
Posts (Atom)
Expand your network at ease : Six Degrees of Separation! PC: Psych2Go Did you know that you are just six connections away from any person ...

-
Why I started blogging... Well, this is the ultimate question I get asked when I tell people I started a blog! I have taken a lot of time to...
-
RTO = Recovery Time Objective tells how quickly you will able to resume the normal operations back by connecting users to the data. ...
-
Just couple of days back I wrote a post on IE9 beta release . I saw it buggy and was wondering if some of you has problem uninstalling this ...