Archive

Archive for December, 2013

Commenting in Shell Script

December 27, 2013 Leave a comment
Commenting Shell Script

#!/bin/bash
echo "PreProcessing"
<<COMMENT_HERE
whatever will go here
and here ..
COMMENT_HERE
echo "Further Processing"

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

if false
then
Everything else here for Testing!!!
fi

EDITED: Got more information here http://stackoverflow.com/questions/1444367/commenting-out-a-set-of-lines-in-a-shell-script

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/id_rsa.pub | ssh bhs@BHS ‘cat >> .ssh/authorized_keys’

Testing
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 smtp.gmail.com:465 | 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
                                                             SSL,S/MIME,JAR/XPI

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://smtp.gmail.com:587
 set smtp-auth=login
 set smtp-auth-user=data.insights@me.com
 set smtp-auth-password=passwd
 set from=”data.insights@me.com (My Insights)”
 }

Testing mail Config

 echo “Test Email” | mailx  -v -A gmail -s “test” zubair.ahmed@me.com

Categories: HOWTOs

Date Range in Shell script

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

20130101 20130102
20130102 20130103  

 startdate=20130315
 enddate=20130414
 
 curr=”$startdate”
 while true; do
     #echo “$curr”
     [ “$curr” \< "$enddate" ] || break
     next=$( date +%Y%m%d –date “$curr +1 day” )
     echo “$curr $next”
     curr=$next
 done
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...  
./script1.sh 1>/dev/null 2>&1 &  pid1=$!  
./script2.sh 1>/dev/null 2>&1 &  pid2=$!  
./script3.sh 1>/dev/null 2>&1 &  pid3=$!  
./script4.sh 1>/dev/null 2>&1 &  pid4=$!    

# Wait for processes to finish...  
echo -ne "Commands sent... "  
wait $pid1  
err1=$?  
wait $pid2  
err2=$?  
wait $pid3  
err3=$?  
wait $pid4  
err4=$?    

# Do something useful with the return codes...  
if [ $err1 -eq 0 -a $err2 -eq 0 -a $err3 -eq 0 -a $err4 -eq 0 ]  
then      
echo "pass"  
else      
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:

    ./Script.sh 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