This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkprocess() { | |
local process=$1 | |
[[ $# -ne 1 ]] && { echo "Usage: $0 process"; exit 1; } | |
if ps cax | grep -q $process; then | |
echo "Process is running." | |
else | |
echo "Process is not running." | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CheckSpace() { | |
local Partition=$1 | |
awk -v p=$Partition 'BEGIN{ | |
threshold=80 | |
cmd = "LC_ALL=C df -Ph "p | |
while( cmd | getline ) { | |
used=$5 # Usage in % of 5th colume | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function AppendIfnotExists() { | |
while read s | |
do | |
inputFile="$2" | |
# if starting content matched then comment them | |
local startStr=$( echo "${s}" | cut -d" " -f1 ) | |
grep -q "^#${s}" $inputFile || sed -i "s/^$startStr/#$startStr/g" $inputFile | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Function will handal escaped character / also using sed | |
CommentAppend() { | |
# Comment line and append line below commented line | |
local comment="$( echo "$1" | sed 's/\(\/\)/\\\//g' )" # search this line and comment it | |
local append="$( echo "$2" | sed 's/\(\/\)/\\\//g' )" # Append this line below commented line | |
local InputFile="$3" | |
sed -i "s/^${comment}/#${comment}/g" $InputFile | |
# if string does not exists in input file then add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CheckLoadadv() { | |
# Set threshold value | |
local Threshold=$1 | |
# if threshold not specify then take deafault 6 | |
(( $Threshold )) || Threshold=6 | |
# get input values from /proc/loadavg file | |
local Current_loadadv="$(cut -d" " -f1 /proc/loadavg )" | |
# take first value from inputdata | |
local Cur_int_loadadv="${Current_loadadv/.*}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GetTopProcess() { | |
ps --no-headers -eo "%cpu,%mem,cmd,etime" | | |
sort -t. -k1 -r | | |
head -10 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
status_msg() { | |
local status=$? | |
local failed="$(tput bold)$(tput setf 4)[failed]$(tput sgr0)" | |
local succeeded="$(tput bold)$(tput setf 2)[succeeded]$(tput sgr0)" | |
(( $status == 0 )) && | |
echo $succeeded || | |
echo $failed | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flotToint() { | |
printf "%.0f\n" "$@" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YesOrNo() { | |
while : | |
do | |
read -p 'Do you want to Continue (yes/no?): ' answer | |
case "${answer}" in | |
[yY]|[yY][eE][sS]) exit 0 ;; | |
[nN]|[nN][oO]) exit 1 ;; | |
esac | |
done | |
} |
OlderNewer