#!/usr/bin/ksh
tail -f /ms/user/s/shettkus/bcp.C18.LedgerJournal.log | {
while read myline; do
lines_read=`echo $myline| cut -d ” ” -f 1`
expr $lines_read + 0 > /dev/null 2>&1
if [ $? -eq 0 ]
then
done=1.0;
done=`echo $done*100*$lines_read/108406239 | bc -l`
#done=$(($done*100))
int_done=$((100*$lines_read/108406239))
i=1
printf “|”
while [[ $i -le $int_done ]]
do
printf “#”
i=$(($i+1))
done
i=$(($int_done+1))
while [[ $i -le 100 ]]
do
printf ” “
i=$(($i+1))
done
printf “| “
printf “%.4f%%” $done
if [[ $int_done -eq 100 ]]
then
printf “\n”
exit
fi
printf “\b\b\b\b\b\b\b\b\b”
i=100
while [[ $i -ge 0 ]]
do
printf “\b”
i=$(($i-1))
done
printf “\b”
fi
done }
vimrc
June 11, 2008This is my .vimrc file:
hi Comment ctermfg=5
set nu
set ts=2
set ai
set foldmethod=marker
set foldcolumn=1
set foldtext=MyFoldText()
function MyFoldText()
let line=getline(v:foldstart)
let sub = substitute(line, ‘##{{{‘,”,’g')
return v:folddashes . sub
endfunction
highlight Folded ctermbg=0
highlight Folded ctermfg=7
highlight foldColumn ctermbg=0
highlight foldColumn ctermfg=7
Sendmail in a shell script
May 28, 2008Someone asked me to write a script that will send mails to a particular email id. I had not used any such script before. So I had to search quite a lot. Here is the simple shell script that will send mail to the specified email ids. Currently it does not support attachments.
#!/usr/bin/ksh
#———————————————————————-
# Name: SendMail
# Purpose: To send mails using the sendmail command
# Usage: SendMail
# Owner: Ketan Joshi
# Setting: Just change the variables at the start of the script to
# appropriate values. Create a message by modifying the string BODY
# You can even have html tags in the body.
# Limitation: Currently, this does not support attachments.
#——————————————————————–
#Temporary file for containing the mail message
tmp=/tmp/mail-body-`date +%F`;
touch $tmp && chmod 600 $tmp;
#Set up the various headers for sendmail to use
TO=’ketan.joshi@oracle.com,saurabh.abhishek@oracle.com’;
CC=”;
FROM=’ketan.joshi@yahoo.com’;
SUBJECT=’Test Mail’;
MIMEVersion=’1.0′;
CONTENTType=”text/html; charset=us-ascii”;
#Here write the content of your mail.
BODY=”
<b>Hello from ketan.</b>
This is test mail.
“;echo Sending the mail.
echo -e “To: $TO” > $tmp;
echo -e “Cc: $CC” >> $tmp;
echo -e “From: $FROM” >> $tmp;
echo -e “Content-Type: $CONTENTType”>>$tmp;
echo -e “MIME-Version: $MIMEVersion”>>$tmp;
echo -e “Subject: $SUBJECT”>>$tmp;
echo -e “Body: $BODY”>>$tmp;/usr/sbin/sendmail -t < $tmp;
rm -rf $tmp;
Taking backup of your files
May 22, 2008Here is a small script that will automatically create a backup directory and take a backup of your files.
The script needs many improvements but, in its simplest form, I found it useful. I’ll improve it as and when I get some time.
#! /usr/bin/ksh
echo “Backing up $1″;
file=$1;
vDate=`date +%Y%m%d_%H%M%S%p`;
# User can mention relative or full path of the filename.
# in this case, extract the basename.
#fileName=split(‘/’,$1)
newFile=${file%\.*}_$vDate.${file##*.};
if [[ $1 = "" ]]
then
echo “Usage: backup <filename>”
exit;
fi
if ! [ -d 'bkp' ]
then
echo “bkp directory is not present. Creating the same.”
mkdir bkp;
fi
echo “copying $1 to bkp/${newFile}”;
cp $1 ./bkp/${newFile};
chmod -wx ./bkp/${newFile};
How to use this?
I have saved this script as “backup” and given it execute permission.
To take a backup of a file, run the following command at command prompt:
$ backup <filename>
This will first check if a directory “bkp” is present in the current directory. If not, it will create it and copy the file to it with name changed to reflect the date and time of copying.
Currently, it handles only one file at a time, I need to modify this to handle multiple files. But I guess I will do that in Perl instead of shell as it looks simpler.
Posted by KeJo
Posted by KeJo
Posted by KeJo