Archive for December, 2013

Commenting in Shell Script

December 27, 2013 Leave a comment
Commenting Shell Script
echo "PreProcessing"
whatever will go here
and here ..
echo "Further Processing"

--------- OR ---------

if false
Everything else here for Testing!!!

EDITED: Got more information here

Categories: HOWTOs

Passwordless login from ahmed@AMD to bhs@BHS server.

December 26, 2013 Leave a comment
Passwordless login from ahmed@AMD to bhs@BHS server.
Use the 3 simple commands below.
ahmed@AMD:~> ssh-keygen -t rsa
ahmed@AMD:~> ssh bhs@BHS mkdir -p .ssh
ahmed@AMD:~> cat ~/.ssh/ | ssh bhs@BHS ‘cat >> .ssh/authorized_keys’

ahmed@AMD:~> ssh bhs@BHS 
Categories: HOWTOs

Installing and Config heirloom-mailx (Gmail) on centos/ubuntu

December 24, 2013 Leave a comment
Creating certificate Directory for SSL/TLS auth for Gmail
# Create a certificate directory
~]$ mkdir .certs

# Create a new database in the certs dir
~]$ certutil -N -d .certs 

# Fetch the certificate from Gmail, saving in the text file GMAILCERT
~]$ echo -n | openssl s_client -connect | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > GMAILCERT

# Import the new cert file into the new database in the new dir
~]$ certutil -A -n “Google Internet Authority” -t “C,,” -d .certs -i GMAILCERT 

# Double Check
~]$ certutil -L -d .certs

Certificate Nickname                                         Trust Attributes

Google Internet Authority                                    C,,  
Mail .mailrc file
 account gmail {
 set smtp-use-starttls
 set ssl-verify=ignore
 set nss-config-dir=~/.certs
 set smtp=smtp://
 set smtp-auth=login
 set smtp-auth-password=passwd
 set from=” (My Insights)”

Testing mail Config

 echo “Test Email” | mailx  -v -A gmail -s “test”

Categories: HOWTOs

Date Range in Shell script

December 9, 2013 Leave a comment
Date in formar yyyymmdd
Output as 

20130101 20130102
20130102 20130103  

 while true; do
     #echo “$curr”
     [ “$curr” \< "$enddate" ] || break
     next=$( date +%Y%m%d –date “$curr +1 day” )
     echo “$curr $next”
Categories: HOWTOs

Execute multiple shell scripts concurrently

December 7, 2013 Leave a comment
that seems to do exactly what you want.
    # Start the processes in parallel...  
./ 1>/dev/null 2>&1 &  pid1=$!  
./ 1>/dev/null 2>&1 &  pid2=$!  
./ 1>/dev/null 2>&1 &  pid3=$!  
./ 1>/dev/null 2>&1 &  pid4=$!    

# Wait for processes to finish...  
echo -ne "Commands sent... "  
wait $pid1  
wait $pid2  
wait $pid3  
wait $pid4  

# Do something useful with the return codes...  
if [ $err1 -eq 0 -a $err2 -eq 0 -a $err3 -eq 0 -a $err4 -eq 0 ]  
echo "pass"  
echo "fail"  fi
Note that this captures the exit status of the script and not what it outputs to stdout. There is no easy way of capturing the stdout of a script running in the background, so I would advise you to use the exit status  to return information to the calling process.
Categories: Others

Script – Standard in, out, and error — Meaning of "> /dev/null 2>&1"

December 7, 2013 Leave a comment

in your .vimrc:

    ./ 1>$LOGGER_BASE_PATH/Script_$CURRENTTIME.log 2>&1 &

Standard in, out, and error

There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it’s an interactive program, or from another program if it’s processing the other program’s output. The program usuallyprints to standard output, and sometimes prints to standard error. These three file descriptors (you can think of them as “data pipes”) are often called STDIN, STDOUT, and STDERR.

Sometimes they’re not named, they’re numbered! The built-in numberings for them are 0, 1, and 2, in that order. By default, if you don’t name or number one explicitly, you’re talking about STDOUT.

Given that context, you can see the command above is redirecting standard output into /dev/null, which is a place you can dump anything you don’t want (often called the bit-bucket), then redirecting standard error into standard output (you have to put an & in front of the destination when you do this).

The short explanation, therefore, is “all output from this command should be shoved into a black hole.” That’s one good way to make a program be really quiet!

Categories: Others

Renaming all files to "lowercase" in a Directory

December 7, 2013 Leave a comment
rename 'y/A-Z/a-z/' *
Categories: Others