Search This Blog

Wednesday, October 16, 2013

Colourise  your shell scripts
#!/usr/bin/ksh
#----------------------------------------------------------------------------------------------
#                       Define Colours for scripts.
#
#       Written : Stan Lovisa
#       Date    : 26-10-2012
#       Mod     :
#
# Black         0;30     Dark Gray      1;30
# Blue          0;34     Light Blue     1;34
# Green         0;32     Light Green    1;32
# Cyan          0;36     Light Cyan     1;36
# Red           0;31     Light Red      1;31
# Purple        0;35     Light Purple   1;35
# Brown         0;33     Yellow         1;33
# Light Gray    0;37     White          1;37
# 0 normal, 1 bold, 4 underline, 7 reverse video
#----------------------------------------------------------------------------------------------
#
#       Notes. How to use.
#
#       printf "${TXTGREEN}"    To switch on colour.
#       printf "${TXTNC}"       To switch off colour.
#
#----------------------------------------------------------------------------------------------
TXTRED="\033[1;31m"
TXTREDRV="\033[7;31m"
TXTLBLUE="\033[1;34m"
TXTBLUERV="\033[7;36m"
TXTGREEN="\033[0;32m"
TXTGREENRV="\033[7;32m"
TXTYELLOW="\033[1;33m"
TXTYELLOWRV="\033[7;33m"
TXTNC="\033[1;0m"




Thursday, July 11, 2013

Scripting SMTP
SMTP: Using smtp commands in a shell script when sendmail isn't setup.




LOG="/tmp/${0##*/}.log"
SUBJECT="${0##*/}"
MAILSERVER=mailhost
PORT="25"
MAILFROM="user1@domain user2@domain"
MAILLIST="email@somedomain"
#------------------------------------------------------------------------
mailto()
{
exec 3<>/dev/tcp/$MAILSERVER/$PORT
if [ $? -ne 0 ]
then
echo
echo "ERROR: Cannot connect to the Mail Server"
echo "Please check the servername and/or the port number"
exit
fi
echo -en "HELO ${MAILSERVER}\r\n" >&3
echo -en "MAIL FROM:$MAILFROM\r\n" >&3
for MAILTO in ${MAILLIST}
do
echo -en "RCPT TO:$MAILTO\r\n" >&3
done
echo -en "DATA\r\n" >&3
echo -en "Subject: $SUBJECT\r\n\r\n" >&3
echo -en "$(cat ${LOG})\r\n" >&3
echo -en ".\r\n" >&3
echo -en "QUIT\r\n" >&3
cat <&3
}
#------------------------------------------------------------------------
Some commands
.
.
mailto