restart or invoke a shell script from inside in linux



As an Unix or Database Administrator, we often write a shell script to perform maintenance task which can be called manually , in crontab or scheduled in deployment pipeline.


Requirement to invoke a shell script within a single call helps to reuse the input's passed such as  password , file name or any other input variable.


The EASY method to do the same is by recalling shell script within a shell script again ...


#!/bin/sh

sh test.sh $0 $1


The SMART way to do the same is by using the goto method to call a block for re-invoking a part of the code ...


#!/bin/sh

goto()
{
echo "Part of Code to be invoke repeatedly.." 
}

while true; do

 echo -n "Proceed Y/N:"
read INPUT

 if [ $INPUT == "Y" ] ; then
    goto;
else
    break
    exit
fi

done



No comments:

Post a Comment