Skip to main content

Posts

Showing posts from December, 2013

Commenting in Shell Script

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

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

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 sm

Date Range in Shell script

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

Execute multiple shell scripts concurrently

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

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

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  usually prints 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 re

How to check if a directory exists in a shell script

To check if a directory exists in a shell script you can use the following: if [ - d "$DIRECTORY" ]; then # Control will enter here if $DIRECTORY exists. fi Or to check if a directory doesn't exist: if [ ! - d "$DIRECTORY" ]; then   # Control will enter here if $DIRECTORY doesn't exist.   fi subsequent commands may not work as intended if you do not take into account that a symbolic link to a directory will also pass this check. E.g. running this: ln - s "$ACTUAL_DIR" "$SYMLINK"   if [ - d "$SYMLINK" ]; then   rmdir "$SYMLINK"   fi Will produce the error message: rmdir: failed to remove `symlink': Not a directory So symbolic links may have to be treated differently, if subsequent commands expect directories: if [ - d "$LINK_OR_DIR" ]; then   if [ - L "$LINK_OR_DIR" ]; then