SH Script replaces the whole line in Config file :
#!/bin/bash
# content of your script
function goto
{
label=$1
cmd=$(sed -n "/^:[[:blank:]][[:blank:]]*${label}/{:a;n;p;ba};" $0 |
grep -v ':$')
eval "$cmd"
exit
}
start=${1:-"start"}
### Check Java Version ##
if type -p java; then
_java=java
else
echo "Not able to find Java. Please check your java instalation."
exit 0
fi
if [[ "$_java" ]]; then
version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
if [[ "$version" < "8.0" ]]; then
echo "Error : java version is too low. At least Java >= 8.0 needed."
exit 0
fi
fi
### END Check Java Version ##
### User Location Path Input ##
: start
read -p "Enter Home Location/path : " inputPath
### User Location Path Validation ##
if [ -z "$inputPath" ]
then
echo "Location/Path should not be empty or blank!"
goto "start"
fi
### Check for dir, if not found create it using the mkdir ##
[ ! -d "$inputPath" ] && mkdir -p "$inputPath"
### User Name Validation ##
: usrName
read -p "Enter User Name : " userName
if [ -z "$userName" ]
then
echo "User name not be empty or blank!"
goto "usrName"
fi
### User Password Validation ##
: usrPassword
read -p "Enter Password : " password
if [ -z "$password" ]
then
echo "Password should not be empty or blank!"
goto "usrPassword"
fi
## Replace User Name in Config ##
arr=( $(awk '/User.Name/{print NR}' Config) )
sed ${arr[0]}' c\User.Name : '$userName Config > temp_file
cat temp_file > Config
rm -rf temp_file
# Replace Password in Config
arr=( $(awk '/User.Pasword/{print NR}' Config) )
sed ${arr[0]}' c\User.Pasword : '$password Config > temp_file
cat temp_file > Config
rm -rf temp_file
### copy Config file ##
cp Config $inputPath
Domain Name : www.ccc.com User.Name : uuuuuu User.Pasword : ppppppp SMTP domain : SDFGjk
bat script
ReplyDelete@echo off
SetLocal EnableDelayedExpansion
rem check java version
rem if java not installed then exited
rem execute only if java veresion is greater than or equal to 8
set JAVAVER=9.0
rem where java >nul 2>nul
rem if %errorlevel%==1 (
rem echo Not able to find java. Please check your Java instalation.
rem pause
rem exit
rem )
for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do (
set JAVAVER=%%g
)
if %JAVAVER% LSS 8.0 (
echo Error : Java version is too low At least Java should be greater then 8.0
pause
exit
)
rem insert sourceDirectory
:sourceDirectoryPoint
set /p sourceDirectory=Enter Source Directory:
if "%sourceDirectory%"=="" (
echo Source Directory should not be empty or blank.
goto sourceDirectoryPoint
)
if not exist %sourceDirectory% (
echo %sourceDirectory% does not exist in system.
echo Creating Source Directory...
set /p sourceDrive=Enter absolete path:
md "!sourceDrive!\Source"
set sourceDirectory=!sourceDrive!\Source
)
rem insert workDirectory
:workDirectoryPoint
set /p workDirectory=Enter Work Directory:
if "%workDirectory%"=="" (
echo Work Directory should not be empty or blank.
goto workDirectoryPoint
)
if not exist %workDirectory% (
echo %workDirectory% does not exist in system.
echo Creating Work Directory...
:workDrivePoint
set /p workDr=Enter absolete path:
if "!workDr!"=="" (
echo Work Directory should not be empty or blank.
goto workDrivePoint
) else (
md "!workDr!\ERP"
set workDirectory=!workDr!\ERP
)
)
rem create folder config, failed, processed, logarchive
md "%workDirectory%\config"
md "%workDirectory%\failed"
md "%workDirectory%\processed"
md "%workDirectory%\logarchive"
set source=Config.txt
set target=Output.txt
rem copy batch file, jar & config file to work directory
xcopy /s final.bat %workDirectory% > local
xcopy /s uut.zip %workDirectory% > local
rem xcopy /s config.txt %workDirectory%\config
rem insert Username
:userPoint
set /p usrname=Enter User Name:
if "%usrname%"=="" (
echo User Name should not be empty or blank.
goto userPoint
)
rem insert password
:pwdPoint
set /p pwd=Enter Password:
if "%pwd%"=="" (
echo Password should not be empty or blank.
goto pwdPoint
)
rem ##########################################
rem update user name in Config file
set clientIdSeachString=vertex.validation.clientid
set clientIdReplaceLine=vertex.validation.clientid : %usrname%
if exist %target% del %target%
for /F "delims=" %%a in ('type %source%') do (
set line=%%a
echo %%a | find /i "%clientIdSeachString%" && set line=%clientIdReplaceLine%
echo !line! >> %target%
)
del Config.txt
rename "Output.txt" "Config.txt"
xcopy /s Config.txt %workDirectory%\config > local
del local