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
Monday, January 31, 2011
Apache: Track how much time a request took
To track the time taken to server a request by apache is just a matter of adding one extra parameter in your config file and this is how you do that -
Once you make the config changes live by restarting your apache server, tail the access logs and you will now see the
172.28.90.21 - - [31/Jan/2011:21:29:15 -0800] "GET /repos/ HTTP/1.1" 401 401 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13" 0/446
Hope it helps someone. Thanks/-
-Debu
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T/%D" combined
So if you see we have added only two additional parameters -
%T = The time taken to serve the request, in seconds.%D = The time taken to serve the request, in microseconds.Once you make the config changes live by restarting your apache server, tail the access logs and you will now see the
the time spent to serve the request at the end of the line, along with other access logs parameters.172.28.90.21 - - [31/Jan/2011:21:29:15 -0800] "GET /repos/ HTTP/1.1" 401 401 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13" 0/446
Hope it helps someone. Thanks/-
-Debu
Wednesday, January 26, 2011
Linux way of selctive backups
Sometimes we have a choice of only backing up some of the selected files from an
application or some other very crucial files. Below is how I do it in a real quick way:
cat >> /etc/bkup.conf
/usr/local/apache/conf/httpd.conf
/usr/local/apache/conf/httpd.global.conf
/usr/local/apache/conf/httpd.mod_jk.conf
/usr/local/apache/conf/vhosts/*
/usr/local/apache/conf/httpd.vhosts.include.conf
/usr/local/apache/conf/httpd.ssl.conf
EOF
Then I run tar command with -T flag pointing to the file which contains
the list. In my case it is /etc/bkup.conf
tar -cjf bkup-WebConfig-`date +%Y-%m-%d`.tar.bz2 -T /etc/bkup.conf
And you have your selective backup ready!
Thanks/-
DEBAJIT
application or some other very crucial files. Below is how I do it in a real quick way:
cat >> /etc/bkup.conf
/usr/local/apache/conf/httpd.conf
/usr/local/apache/conf/httpd.global.conf
/usr/local/apache/conf/httpd.mod_jk.conf
/usr/local/apache/conf/vhosts/*
/usr/local/apache/conf/httpd.vhosts.include.conf
/usr/local/apache/conf/httpd.ssl.conf
EOF
Then I run tar command with -T flag pointing to the file which contains
the list. In my case it is /etc/bkup.conf
tar -cjf bkup-WebConfig-`date +%Y-%m-%d`.tar.bz2 -T /etc/bkup.conf
And you have your selective backup ready!
Thanks/-
DEBAJIT
Thursday, November 25, 2010
Server is Baremetal or VMWare?
Usually you can type one of the following commands to see if the server you are in is VMWare VM.
[root@VM001 ~]# /sbin/lspci | grep -i vmware
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
[root@qypprdestws03 ~]# grep -i vmware /proc/scsi/scsi
Vendor: VMware Model: Virtual disk Rev: 1.0
Vendor: VMware Model: Virtual disk Rev: 1.0
[root@VM001 ~]# dmidecode | grep -A4 "System Information"
System Information
Manufacturer: VMware, Inc.
Product Name: VMware Virtual Platform
Version: None
Serial Number: VMware-50 00 6e c3 df 0c 97 f1-3e 99 9d 8b 66 a0 8e 24
[root@VM001 ~]#
Thanks/-
[root@VM001 ~]# /sbin/lspci | grep -i vmware
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
[root@qypprdestws03 ~]# grep -i vmware /proc/scsi/scsi
Vendor: VMware Model: Virtual disk Rev: 1.0
Vendor: VMware Model: Virtual disk Rev: 1.0
[root@VM001 ~]# dmidecode | grep -A4 "System Information"
System Information
Manufacturer: VMware, Inc.
Product Name: VMware Virtual Platform
Version: None
Serial Number: VMware-50 00 6e c3 df 0c 97 f1-3e 99 9d 8b 66 a0 8e 24
[root@VM001 ~]#
Thanks/-
Thursday, October 28, 2010
Forgot to use sudo?
Has it happened to you before that - you run a command and forgot to 'sudo' - and hence the commnd fails and now you need to re-run the command all over again? Well in that case this is how you can save some time.
[debu@DebaTestBox ~]$ sudo !!
Forgot 'sudo' before editing a file:
Believe me this is the most frustrating one, and it happens to me a lot to me. You edited quite a few in the file and when try to save&xit( :wq!) you see an error as below
E212: Can't open file for writing
Press ENTER or type command to continue
Well, the below is a savior un this kind of scenario
:w !sudo tee %
this will ask your password the there in, and you are done. All your edits are now recorded by Vim editor.
Cheers!!!
Hope it helps!
DK
[debu@DebaTestBox ~]$ sudo !!
Forgot 'sudo' before editing a file:
Believe me this is the most frustrating one, and it happens to me a lot to me. You edited quite a few in the file and when try to save&xit( :wq!) you see an error as below
E212: Can't open file for writing
Press ENTER or type command to continue
Well, the below is a savior un this kind of scenario
:w !sudo tee %
this will ask your password the there in, and you are done. All your edits are now recorded by Vim editor.
Cheers!!!
Hope it helps!
DK
Monday, October 25, 2010
ssh client for BlackBerry!
I have been using BlackBerry for quite sometime now - and recently someone asked whether I can have any ssh client there.
Yes! We can. I use MidpSSH, which is a ssh client for MIDP 1.0 / 2.0 (J2ME) devices such as Java capable cellphones and other mobile devices released and distributed under GPL.
So far no issues - and its cool. Here is the link to download -
http://www.xk72.com/midpssh/download.php
You will need to convert .jar/.jad to .alx files
Cheers!
DK
Yes! We can. I use MidpSSH, which is a ssh client for MIDP 1.0 / 2.0 (J2ME) devices such as Java capable cellphones and other mobile devices released and distributed under GPL.
So far no issues - and its cool. Here is the link to download -
http://www.xk72.com/midpssh/download.php
You will need to convert .jar/.jad to .alx files
Cheers!
DK
Subscribe to:
Posts (Atom)
🔭 First Impression: Exploring Grafana Mimir ... After Years with Thanos! Not an observability( OE ) purist, but I do appreci...
-
RTO = Recovery Time Objective tells how quickly you will able to resume the normal operations back by connecting users to the data. ...
-
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...
-
Effective Time-management and Time-boxing is a concern for 'always ready people'. Being from a background that I am from, I am...