1) # Script To Display: Sum As
1) # Script To Display: Sum As
biz/monitoring/find-null-password-accounts/
if [ $choice -eq 1 ]
then
answer="$n1 x $n2 = $(( $n1 * $n2 ))"
elif [ $choice -eq 2 ]
then
answer="$n1 - $n2 = $(( $n1 - $n2 ))"
elif [ $choice -eq 3 ]
then
Answer="$n1 % $n2 = $(( $n1 % $n2 ))"
elif [ $choice -eq 4 ]
then
answer="$n1 / $n2 = $(( $n1 / $n2 ))"
else
echo "Sorry please select number between 1-4 only"
exit 1
fi
echo $answe
2)#!/bin/bash
# Shell script to read 3 numbers and find the greaters of the three
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
echo -n "Please enter three numbers (separate number by space) : "
read a b c
# compare a with b and c. Note -a is logical and operator
if [ $a -gt $b -a $a -gt $c ]
then
big=$a
elif [ $b -gt $a -a $b -gt $c ] # compare b with a and c
then
big=$b
elif [ $c -gt $a -a $c -gt $b ] # compare c with a and b
then
big=$c
elif [ $a -eq $b -a $a -eq $c -a $b -eq $c -a $c -eq $b ] # see if all of
them are equal or not
then
big="All three numbers are same (equal)"
else # something must be wrong if we are here, like one of number is
character such as 'A'
big="Can not guess greaters of three numbers"
fi
# display resul
3)#!/bin/bash
# Shell script to read a number and write the number in words. Use case
# control structure. For example 12 should be print as one two
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
len=$(echo $n | wc -c)
len=$(( $len - 1 ))
sd=0
char=""
echo -n "Enter a one character : "
read char
# use sed command to determine input character is digit or not
# -e : start script
# s/[0-9]// : Attempt to match regex [0-9] i.e. all digit against the pattern
space (echo $char).
# If successful, replace that portion matched with replacement i.e. //
do nothing.
# g : Global replacement
# so if digit are in input it will replace all those digit, and if input is
only digit, nothing
# is left i.e. string is zero and that is what tasted with -z
if [ -z $(echo $char | sed -e 's/[0-9]//g') ]
then
echo "$char is Number/digit"
elif [ -z $(echo $char | sed -e 's/[A-Z]//g') ] # find out if character is
upper
then
echo "$char is UPPER character"
# overwrite file, this is bash specific a better solution is cat > $FILE
>$FILE
for u in $USERS
do
p=$(pwgen -1 -n 8) # create random password
echo "$u:$p" >> $FILE # save USERNAME:PASSWORD pair
done
echo ""
echo "Random password and username list stored in $FILE file"
echo "Review $FILE file, once satisfied execute command: "
echo "chpasswd < $FILE"
# Uncomment following line if you want immediately update all users password,
# be careful with this option, it is recommended that you review $FILE first
# chpasswd < $FILE
10) #!/bin/bash
# Shell script to Finding Accounts with No Password
# Useful to improve system security
# Copyright (c) 2005 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# For more info, please visit:
# http://cyberciti.biz/shell_scripting/bmsinstall.php
# TODO
# - Disable all account w/o password
# - Send an email to admin
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
SPATH="/usr/local/etc/bashmonscripts"
INITBMS="$SPATH/defaults.conf"
[ ! -f $INITBMS ] && exit 1 || . $INITBMS
if ( isRootUser ); then
$GREP -v -E "^#" $SHADOW_FILE | $AWK -F: '$2 == "" { print $1 }'
else
echo "Permission denied [$($ID -u)]"
fi
11) #!/bin/bash
# Script to display the text entered by the user in bold
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http:>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
# read man page of tput command.
echo -n "Enter text : "
read text
echo "Here is what you entered "
# use tput command to display it in bold
tput bold
echo "$text"
echo -n "Press any key to continue..."
# okay turn of bold effect
read key
# it will clear screen too
tput reset
12) !/bin/bash
# Shell program to display numbers from 1 to 10
# -----------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
13) #!/bin/bash
# Shell script to read 5 digit number and calculate the sum of digit
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# use loop to go throug all digit one by one and calculate sum of digit on
fly
for (( i=1; i <= $len; i++ ))
do
sum=$(( $sum + $(echo $n | cut -c $i) ))
done
echo "Sum of $n is $sum"