Bash may refer to: read more at WikiPedia

  • oracle_logo3

    The Oracle WebLogic 11g application server product line is the industry's most comprehensive Java platform for developing, deploying, and integrating enterprise applications. It provides the foundation for application grid, which is an architecture that enables enterprises to outperform their competitors while minimizing operational costs.

    Some notes

    This script may look unsecure (and it is)

    Since password are store inside (admin server login: admin and password is admin), by doing so I can restart Oracle Weblogic in a cron job since stopping wont query the console for the login and password: feel free to remove these lines in blue

    I always recommend to install web process in its own user group and use a dedicated user to mitigate any securities issues:

    # groupadd weblogic
    # useradd -g weblogic-c weblogicuser for weblogic' -m weblogic
    # su – weblogic

    Install then weblogic in /home/weblogic

    Respect the order of component for starting

    1. Start Weblogic Node Manager,
    2. Start WebLogic Admin server,
    3. Start all Managed Server in any order.

    and stopping components

    1. Stop the Node Manager
    2. Stop all Managed WebLogic server
    3. Stop WebLogic

    Names of the managed server

     managed server names are in the script so add remove start and stop command for them

    Logs files of start and stop operations

    are written in 2 files, that use timestamp, see WLS_LOG_START and WLS_LOG_STOP

    /etc/init.d/weblogic file

    Create a new file as root in /etc/init.d/weblogic

    # vi /etc/init.d/weblogic

    and paste inside the following

    # description: webLogic adminServer and managedServer start script

    # customized below to your likings
    WLS_LOG_START=${WLS_BASE}/logs/start.`date '+%d%m%y'`.log
    WLS_LOG_STOP=${WLS_BASE}/logs/stop.`date '+%d%m%y'`.log

    export JAVA_OPTIONS

    if [ ! -f $WLS_HOME/ ]
        echo "WebLogic startup: cannot $WLS_HOME/ "

    su - $WLS_OWNER -c "nohup $WLS_NODE_HOME/ > ${WLS_LOG_START} 2>&1 &"
    sleep 10
    su - $WLS_OWNER -c "nohup $WLS_HOME/ >> ${WLS_LOG_START} 2>&1 &"
    sleep 10
    su - $WLS_OWNER -c "nohup $WLS_HOME/bin/ >> ${WLS_LOG_START} 2>&1 &"
    sleep 10
    su - $WLS_OWNER -c "nohup $WLS_HOME/bin/ >> ${WLS_LOG_START} 2>&1 &"
    return 0

    su - $WLS_OWNER -c "nohup $WLS_NODE_HOME/ > ${WLS_LOG_STOP} 2>&1 &"
    sleep 10
    su - $WLS_OWNER -c "nohup $WLS_HOME/bin/ $WLS_MANAGED_SERVER1t3://localhost:$WLS_ADMIN_PORT ${WLS_ADMIN_LOGIN} ${WLS_ADMIN_PWD} >> ${WLS_LOG_STOP} 2>&1 &"
    sleep 10
    su - $WLS_OWNER -c "nohup $WLS_HOME/bin/ $WLS_MANAGED_SERVER2 t3://localhost:$WLS_ADMIN_PORT  ${WLS_ADMIN_LOGIN} ${WLS_ADMIN_PWD}>> ${WLS_LOG_STOP} 2>&1 &"
    sleep 10
    su - $WLS_OWNER -c "nohup $WLS_HOME/bin/ >> ${WLS_LOG_STOP} 2>&1 &"
    return 0

    case "$1" in
            echo "Usage: $0 start|stop|restart"
            exit 1

  • subversion.logo

    If you are using Subversion/CVS, you might have come across the issue where multiple developers working on a set of files are committing without any comments.

    Subversion’s hook scripts provide a powerful way to associate actions with repository events. For example, the pre-commit hook allows you to check — and possibly abort — a transaction before it actually gets committed. I will provide you now two easy Unix bash scripts  that avoid bad developer behaviors:

    • The first one “” is for checking that nobody submit an empty SVN commit comment
    • The second one “” is able to enforce SVN commit comment pattern using regular expressions

    Creating and Installing a Hook Script

    Your Subversion repository already has some template hook scripts. For example, the pre-commit template is in PATH_TO_REPOS/hooks/pre-commit.tmpl. These templates contain instructions on what the hook script does and what parameters it can expect.

    You can hook your own script on the following events

    • start-commit Before the commit transaction starts
    • pre-commit After the commit transaction starts but before the transaction is committed
    • post-commit After the commit transaction completes
    • pre-revprop-change Before a revision property is changed Repository Path,
    • post-revprop-change: After a revision property is changed Repository Path
    • pre-lock: Before the lock being acquired
    • post-lock: After the lock being acquired

    You’ll find examples in the hook directory named

    • post-commit.tmpl
    • pre-unlock.tmpl
    • post-lock.tmpl
    • pre-commit.tmpl
    • start-commit.tmpl
    • post-revprop-change.tmpl
    • pre-lock.tmpl
    • post-unlock.tmpl
    • pre-revprop-change.tmpl

    If you cant find them, brute force your server to locate them

    # find / –name pre-commit


    # locate pre-commit

    On Debian you will find them at


    Create a file pre-commit with that content, nothing force you to put a huge bash script in pre-commit. In my example below, I prefer to divide pre-commit checks in multiple files. The pre-commit hook gives you a way to catch the transaction before it becomes a revision. Subversion passes this hook two parameters:

    1. the path to the root of the repository
    2. the transaction identifier
    set -e
    /data/svn-repos/{yourRepository}/hooks/ "$1" "$2"
    /data/svn-repos/{yourRepository}/hooks/ "$1" "$2"

    Note that after installation, every commit will run these two scripts. Check your permissions, scripts have to be runnable for the user (www-data on debian)

    Avoid empty comment in SVN commits

    Save this file in /data/svn-repos/{yourRepository}/hooks/

    if [`$SVNLOOK log -t $TXN $REPOS` != ""]; then
      echo "" 1>&2
      echo "*** Your commit has been blocked because you did not give any log message or your log message was too short." 1>&2
      echo "Please write a log message describing the purpose of your changes and then try committing again." 1>&2
      exit 1
      exit 0

    Example in Eclipse, if you break the rule


    Enforce SVN commit comment pattern using regular expressions

    Save this file in /data/svn-repos/{yourRepository}/hooks/

    This script use Bash script REGEX capabilities, I check against what could be a typical JIRA issues entry

    If any developer try to use a commit statement not starting with for example PRODUCT-xxxx, the commit will be blocked.

    if [[ `$SVNLOOK log -t $TXN $REPOS` =~ ${regex} ]]; then
      exit 0
      echo "" 1>&2
      echo "*** Your commit has been blocked because you give an invalid commit comment" 1>&2
      echo "Please make your commit comment start with PRODUCT-XXX" 1>&2
     exit 1

    Example in Eclipse, if you break the rule


    Want more?

    You can automated code reviews with Checkstyle using pre-commit script and so Stop rule-breaking code before it enters your code base!


    hook_scripts" target="_blank"> List of some Hook scripts examples written in python/bash

  • First let's refresh some definitions...
    set user ID (SUID)

    The SUID permission causes a script to run as the user who is the owner of the script, rather than the user who started it. It is normally considered extremely bad practice to run a program in this way as it can pose many security problems.

    set group ID (SGID)

    The SGID permission causes a script to run with its group set to the group of the script, rather than the group of the user who started it. It is normally considered extremely bad practice to run a program in this way as it can pose many security problems.

    Latest versions of the Linux kernel will even prohibit the running of shell scripts that have SGID/SUID attribute set.

    Use of the SUID bit on binaries (to run with root privileges, aka &8221;setuid bit&8221;) MUST be limited to those shown in
    the following list:


    The other binaries that were installed with the SUID bit set MUST have this bit removed. Administrators can still run
    these binaries normally, but they are not available for ordinary users. There are also a number of SGID files on the system that are needed, it may depending on the number of tools, or your distribution. Use Google and query the web for the right list ;-)

    Similarly, the SGID bit MUST NOT be used to give group &8221;root&8221; privileges to any binary.
    To generate a list of all SUID/SGID programs on the system simply run the following command:

    # find / -not -fstype ext3 -prune -o \ -type f \( -perm -4000 -o -perm -2000 \) \ -print

    Then, for each file in this list that is not one of the permitted SUID or SGID programs, run the command
    # chmod -s FILE

    to remove the SUID and SGID bits. When done, re-run the find command to verify that the list matches the
    permitted programs.

    I recommend you installing also FAF (File Anomaly Finder) on your server to check periodically for file with too much rights or privileges

  • if you encounter this error while starting oracle

    /etc/init.d/oraemctl start Starting Oracle EM DB Console:
    Environment variable ORACLE_UNQNAME not defined. 
    Please set ORACLE_UNQNAME to database unique name. OK
    One possible solution is to edit the script
    # vi /etc/init.d/oraemctl

    and add the following code in blue

    # oraemctl Starting and stopping Oracle Enterprise Manager Database Control.
    # Script is valid for 10g and 11g versions.
    # chkconfig: 35 80 30
    # description: Enterprise Manager DB Control startup script
    # Source function library.
    . /etc/rc.d/init.d/functions
    case "$1" in
      echo -n $"Starting Oracle EM DB Console:"
      su - $ORACLE_OWNER -c "ORACLE_SID=$ORACLE_SID $ORACLE_HOME/bin/emctl start dbconsole"
      echo "OK"
      echo -n $"Stopping Oracle EM DB Console:"
      su - $ORACLE_OWNER -c "ORACLE_SID=$ORACLE_SID $ORACLE_HOME/bin/emctl stop dbconsole"
      echo "OK"
     echo $"Usage: $0 {start|stop}"

    Use of course the right SID, after that Oracle Enterprise manager will start correctly

    # /etc/init.d/oraemctl start
    Starting Oracle EM DB Console:Oracle Enterprise Manager 11g Database Control Release
    Copyright (c) 1996, 2009 Oracle Corporation.&160; All rights reserved.
    - An instance of Oracle Enterprise Manager 11g Database Control is already running.

  • tatice-linux-tux-10409

    Some useful Bash Linux alias taken from my user profile. If you have a long command that you type frequently consider putting it in as an alias.

    In computing, alias is a command in various command line interpreters (shells) such as Unix shells, 4DOS/4NT and Windows PowerShell, which enables a replacement of a word with another string. It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command. [WikiPedia]

    Description &160;
    Find all directories and and chmod them to rwxr.xr.x alias fixpermD='find . -type d -exec chmod 755 {} \;'
    Find all files and and chmod them to rw.r..r.. alias fixpermF='find . -type f -exec chmod 644 {} \;'
    Both above and set recursively user and user group in one shot alias fixUserAPerms='fixpermF; fixpermD; chown -R userA .;chgrp -R usergrp .'
    Make a directory and all files recursively read only, secure but a pain to maintain. see next&160; alias ro='find . -type f -exec chmod 444 {} \;find . -type d -exec chmod 555 {} \;'
    Make a directory and all files recursively read write, just the time to update your site. alias rw='find . -type f -exec chmod 644 {} \;find . -type d -exec chmod 755 {} \;'
    Lower case all files in current directory alias lowercaseallfiles='for f in *; do mv $f `echo $f | tr [:upper:] [:lower:]`; done'
    List all open connections to your server alias listOpenConnections='lsof –i'
    List all internet connections alias listinternetconnection='netstat –lptu'
    find the 10 biggest in size directories alias dirsizes=’du -cks * | sort -n | tail –10'
    Show open port alias openports='netstat -nape --inet'
  • tatice-linux-tux-10409

    For day to day hacker, they may be more elegant ways to do it (PERL, AWK), but they have work well for me.

    • Upper case file name or variable,
    • Search and replace in all files content recursively,
    • Renaming all files recursively,
    • Renaming all directory recursively,
    • Copying a set of files from one directory to the other and preserving hierarchy.

    Upper case file name or variable

    function toUpper {
    echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'&160;&160;
    # or
    # echo "$1" | tr -s&160; '[:lower:]'&160; '[:upper:]'


    • in a script toUpper “cedric”
    • assign to a variable in a script result=$(toUpper $variable) or result=$(toUpper “cedric”)

    Search and replace in all files content recursively

    This can go through all directories

    • $3 as base directory
    • Search for $1
    • Replace with $2

    function searchAndReplaceRecursively {
    echo "replace '$1' with '$2' in dir '$3'";
    for file in `find $3 -type f`;
    echo -ne ".";
    sed -e 's/'$1'/'$2'/g' $file > /tmp/tempfile.tmp
    mv /tmp/tempfile.tmp $file
    echo "";


    • in a script searchAndReplaceRecursively “cedric” “unix” .

    Renaming all files recursively

    This can go through all directories, renaming all files based on parameters:

    • $3 as base directory,
    • Search for $1 in filename,
    • Replace with $2 in filename.

    function renameFilenameRecursively {
    for file in `find $3 -type f`;
    newFilename=`basename $file | sed -e 's/'$1'/'$2'/g'`;
    dirs=`dirname $file`;
    mv $file $dirs/$newFilename;


    • in a script renameFilenameRecursively “cedric” “unix” .

    Renaming all directory recursively

    This can go through all directories, renaming all directories based on parameters:

    • $3 as base directory
    • Search for $1 in directory name
    • Replace with $2 in directory name
    • in bold, you can put either
      • *$1 the pattern has to be at end of directory name,
      • $1* the pattern has to be at beginning of directory name,
      • *$1* the pattern has to be in the middle of directory name,
      • remove the case all together, the grep $1 filter already the result of the command find.

    function renameDirectoriesRecursively {
    for adir in `find $3 -type d | grep $1`;
    case $adir in
    *$1* )
    newdirname=$( echo "$adir" | sed -e 's/'$1'/'$2'/g' );
    echo Found $adir will be renamed to $newdirname;
    mv $adir $newDirName;


    • in a script renameDirectoriesRecursively “cedric” “unix” .

    Copying a set of files from one directory to the other and preserving hierarchy

    # find . -name $1 -exec cp -r --parents {} $destination \;

  • joomla_cms

    Digital watermarking is the process of possibly irreversibly embedding information into a digital signal. The signal may be audio, pictures or video, for example. If the signal is copied, then the information is also carried in the copy. In visible watermarking, the information is visible in the picture or video. Typically, the information is text or a logo which identifies the owner of the media.[Wikipedia]


    I decide to go with an offline watermarking first, but you can let any Joomla!® extension watermark picture on the fly using php and .htaccess (at the cost of additional CPU server resources).


    Why Watermarking pictures?

    There is a lot of reasons, among others:

    • To limit images stealing, advanced users will still be able to crop/blur your watermark through!
    • To drive more new users/returning visitors to your site, anybody using your images in a forums may want to visit your site if the watermark can be read (don’t use complex logo, except if you have a well known brand)
    • To advertise your online work,


    The first thing to do is to make a backup of your images! applying a watermarking is a non reversible process, usually this mean for Joomla!® to save your /images/stories directory

    You’ll have to decide what size you want your photos to be displayed at and how much space the text or logo will take up. Keep it small enough so as not to ruin the photo.

    Create a watermark using GIMP

    Download the excellent GIMP if not already done.

    Create a new picture with transparent background 

    Using the text tool, create a black or white title, you can also import/create an original logo.

    Save the file using a .png or .gif extension, don’t use .jpg as it don’t handle transparency



    Prepare your Linux server

    My script require you to install ImageMagick

    ImageMagick®  is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

    ImageMagick install in OpenSuse

    As root run

    # zipper in ImageMagick

    ImageMagick install in Debian

    As root run

    # apt-get install ImageMagick


    Support dir name and filename space

    Support space in path and filename, not so easy as you think. Bash force me to use “” around variables to support space in path and use a while loop instead of a for loop to support space in filename.

    Scan you directories

    Scan your directories recursively for all pictures starting starting from the current directory (.).

    Do not watermark all pictures

    I don’t want to apply a watermark to all my pictures, I have decided to check against the size of the images and apply only if a threshold is reach (here all images bigger in width than 1024 pixels). The command identify allow you to retrieve the characteristics of any pictures

    geometry=$(identify $each)

    return for example

    ./desktop.jpg JPEG 1024x819 1024x819+0+0 DirectClass 8-bit 94.8613kb

    Add a bit of Bash REGEX magic (since 2004 with bash 4.0) to correctly identify picture size


    and voila! I can now use $height and $width in my function.


    Do not run the script twice or more

    Do not run the script twice or more on same directory/sub directories, or the watermark will get darker and darker. The code do not check if any watermark already exist, and apply the same watermark over and over pictures that reach the threshold.


    The script must be runnable

    # chmod u+x


    open the file

    # vi

    and change all variables value at the top

    Position of the Text Watermark

    You can position the text using the following Gravity, possible values are: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.

    NorthWest North NorthEast
    SouthWest South SouthEast

    If the -gravity option is present with NorthEast, East, or SouthEast gravity, it gives the distance leftward from the right edge of the image to the right edge of the cropping region. Similarly, if the -gravity option is present with SouthWest, South, or SouthEast gravity, the distance is measured upward between the bottom edges.

    See more details HERE  

    The bash script

    Source Code



    echo "*******************************************"
    echo "* Image Watermarking Script               *"
    echo "* By Cedric Walter - *"
    echo "* Licence GNU/GPL v3 or later              *"
    echo "*******************************************"
    echo " "
    Below this width no watermark will be apllied
    # NorthEast, East, or SouthEast gravity, it gives the distance leftward from the
    # right edge of the image to the right edge of the cropping region. # Similarly, if the -gravity option is present with SouthWest, South, or SouthEast
    # gravity, the distance is measured upward between the bottom edges. WATERMARK_POSITION=northeast Transparency percentage TRANSPARENCY_PERCENTAGE=15 normal user dont change below #this use bash regular expression capabilities regex="([0-9]*)x([0-9]*)" function applyWatermarkForExtension { find $BASEDIR -type f -name "$1" | while read each do geometry=$(identify "$each") echo $geometry if [[ ${geometry} =~ ${regex} ]]; then echo "$geometry matches" i=1 n=${BASH_REMATCH[*]} width=${BASH_REMATCH[$i]} let i++ height=${BASH_REMATCH[$i]} echo width=$width height=$height if [ $width -gt $MIN_PIC_WIDTH ];then echo "Working on $each..." composite -gravity $WATERMARK_POSITION -dissolve $TRANSPARENCY_PERCENTAGE $WATERMARK "$each" "$each" 2> /dev/null echo "... Done!" fi fi done } add new pictures extensions here applyWatermarkForExtension "*.jpg" applyWatermarkForExtension "*.gif" applyWatermarkForExtension "*.png" applyWatermarkForExtension "*.jpeg" exit 0


    Download from my download section.