Shell script example | cpu usage monitoring

#!/bin/sh
memuse=$(ps -p $(pidof java) -o %mem | awk ‘{if(NR>1)print}’);
thresholdVal=50;
if [ $memuse >  $thresholdVal ]; 
then
    message=”Memory usage for jboss service on application server exceeded threshold.nCurrent use is $memuse %.”
    echo -e $message | mail -s “Alert : Memory monitoring UHMB” “prahlad20@gmail.com”;
fi
cpuuse=$(ps -p $(pidof java) -o %cpu | awk ‘{if(NR>1)print}’);
if [ $cpuuse > $thresholdVal ];
then
    message=”CPU usage for jboss service on application server exceeded threshold.nCurrent use is $cpuuse %.”;
    echo -e $message | mail -s “Alert : CPU monitoring UHMB” “prahlad20@gmail.com”;
fi

Window batch scripts

Project folder/sub-folder creation script


@ECHO OFF

rem ############ Author: Prahlad Dutta ############
rem ############ Date: 09/11/2017 #################
rem ############ Description: project folder creation scripts ############

rem Set envrionment variables
set PROJECT_DIR=”D:PrahladProject”
set BKUP_DIR_NAME=”Backup”
set BILL_DIR_NAME=”Bills”
set CODEBASE_DIR_NAME=”Codebase”
set CONTENT_DIR_NAME=”Content Package”
set DEPLOY_DIR_NAME=”Deployment”
set DOC_DIR_NAME=”Documents”
set HTML_DIR_NAME=”HTML”
set WORKSPACE_DIR_NAME=”Workspace”
set TESTING_DIR_NAME=”Testing”

SET /P project_name=Please enter your project name: 
IF “%project_name%”==”” (
ECHO You did not enter your project name! Bye bye!!
echo.
exit
) ELSE (
ECHO Start creating folder for project: %project_name%
mkdir %PROJECT_DIR%%project_name%
echo Project root directory: %PROJECT_DIR%%project_name%, created successfully.
echo ***************Start creating child folders******************
mkdir %PROJECT_DIR%%project_name%%BKUP_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%BILL_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%CODEBASE_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%CONTENT_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%DEPLOY_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%DOC_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%HTML_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%WORKSPACE_DIR_NAME%
mkdir %PROJECT_DIR%%project_name%%TESTING_DIR_NAME%
echo **********Project folder and subfolder created successfully ******
cd %PROJECT_DIR%%project_name%
echo on
start .

)

Setting environment variables


rem ####envpath.bat######

rem set LOGDIR=”D:prahlad’s Systemprahlad document sectionBackupMy_BackupLogs”
rem set COPYFILE=”C:Usersprahlad.duttaAppDataLocalMicrosoftOutlook*.pst”
REM set COPYTO=”D:prahlad’s Systemprahlad document sectionBackupMy_BackupMail_Backup”
set FILE=”*.pst”

set COPYFILE=”C:Usersprahlad.duttaAppDataLocalMicrosoftOutlook*.pst”
set COPYTO=”D:Prahlad_SystemPrahlad DocumentsBackupMy_BackupMail_Backup”

rem ****seting path for one notebooks****
set NOTEBOOK=”C:Usersprahlad.duttaDocumentsOneNote Notebooks”
set TODIR=”D:Prahlad_SystemPrahlad DocumentsBackupMy_BackupOneNote_Backup”

set ALLFILE=”*”

Batch script for login tracker


@echo off

call envpath.bat
set user=%username%


rem ############## for win 7 32-bit###########
rem For /f “tokens=2-4 delims=/ ” %%a in (‘date /t’) do (set MyDate=%%b-%%a-%%c) 

rem ############## for win 7 64-bit###########
for /f “tokens=1” %%a in (‘date /t’) do (set Mydate=%%a)
set logindate=%Mydate%

for /f %%b in (‘time /t’) do (set Mytime=%%b)
set logintime=%Mytime%

for /f “tokens=2 delims= ” %%c in (‘time /t’) do (set Myzone=%%c)
set timezone=%Myzone%

set afile=%user%_Logindetail_%logindate%.log

REM cd %LOGDIR%
IF EXIST %LOGDIR%%afile% (
echo %user% %logindate% %logintime% %timezone% >> %LOGDIR%%user%_Logindetail_%logindate%.log
) ELSE (
echo Loginname Logindate Logintime  > %LOGDIR%%user%_Logindetail_%logindate%.log
echo ———- ———- ———– >> %LOGDIR%%user%_Logindetail_%logindate%.log
echo %user% %logindate% %logintime% %timezone% >> %LOGDIR%%user%_Logindetail_%logindate%.log
)

Batch script for backup your mail


@echo off
call envpath.bat
rem taskkill /f /im outlook.exe
copy %COPYFILE% %COPYTO%
rem ############## for win 7 32-bit###########
rem For /f “tokens=2-4 delims=/ ” %%a in (‘date /t’) do (set MyDate=%%b-%%a-%%c) 
rem ############## for win 7 64-bit###########
set MyDate=%date%
echo %MyDate%
cd %COPYTO%
D:
“c:Program FilesWinRARRar.exe” a -df -r prahlad.dutta_%MyDate%.rar %FILE%
rem “C:Program Files (x86)WinRARRar.exe” a prahlad.dutta_%MyDate%.rar %FILE%
rem del %FILE%
echo .
rem shutdown -s -f -t 60