diff --git a/CpuMemDisk.sh b/CpuMemDisk.sh index 8e986ae..441fe0c 100644 --- a/CpuMemDisk.sh +++ b/CpuMemDisk.sh @@ -4,7 +4,7 @@ # Version:1.0 # Created Date: 2019-05-02 # Modified Date: -# WebSite: https://server-computer.com +# WebSite: https://arkit.co.in # Author: Ankam Ravi Kumar HOSTNAME=$(hostname) diff --git a/Even_or_Odd_Number.sh b/Even_or_Odd_Number.sh new file mode 100644 index 0000000..a8294a1 --- /dev/null +++ b/Even_or_Odd_Number.sh @@ -0,0 +1,10 @@ +#!/bin/bash +## To find given number is Even number or Odd Number + +read -p "Enter a number: " number + +if [ $((number % 2)) -eq 0 ]; then + echo "$number is an even number." +else + echo "$number is an odd number." +fi diff --git a/arkit.co.in-nested-if.sh b/ExamResults.sh similarity index 94% rename from arkit.co.in-nested-if.sh rename to ExamResults.sh index 17d421b..b718bdf 100644 --- a/arkit.co.in-nested-if.sh +++ b/ExamResults.sh @@ -1,7 +1,7 @@ #!/bin/bash #Purpose: Validate and report Student subject marks #Version:1.0 -#Created Date: Wed May 16 19:00:52 IST 2018 +#Created Date: 2024 sep #Modified Date: #Author: Ankam Ravi Kumar # START # diff --git a/convert_and_update_mysql.sh b/convert_and_update_mysql.sh index 0a6436d..98f4d25 100644 --- a/convert_and_update_mysql.sh +++ b/convert_and_update_mysql.sh @@ -3,7 +3,7 @@ n=1 until [ $n -gt 11196 ] do -EXIRECORDS=$(mysql -u root -pmysql -h 192.168.2.100 -e "SELECT sn,tarsize from DATABASE.Table1 where sn='"$n"'" |tail -n1 |grep $n) +EXIRECORDS=$(mysql -u root -pPASSWORD -h 192.168.2.100 -e "SELECT sn,tarsize from DATABASE.Table1 where sn='"$n"'" |tail -n1 |grep $n) RECORDNUMBER=$(echo $EXIRECORDS |awk '{print $1}') FOLDERSIZE=$(echo $EXIRECORDS |awk '{print $2}') @@ -12,28 +12,28 @@ KB=$(echo $EXIRECORDS |awk '{print $2}' |grep K |wc -l) if [ $KB -ge 1 ]; then K=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/K//g') BYTES=$($K * 1024 |bc |awk -F. '{print $1}') - mysql -u root -pmysql -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" + mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" fi MB=$(echo $EXIRECORDS |awk '{print $2}' |grep M |wc -l) if [ $MB -ge 1 ]; then M=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/M//g') BYTES=$(echo $M*1024*1024 |bc |awk -F. '{print $1}') - mysql -u root -pmysql -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" + mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" fi GB=$(echo $EXIRECORDS |awk '{print $2}' |grep G |wc -l) if [ $GB -ge 1 ]; then G=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/G//g') BYTES=$(echo $G*1024*1024*1024 |bc |awk -F. '{print $1}') - mysql -u root -pmysql -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" + mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" fi TB=$(echo $EXIRECORDS |awk '{print $2}' |grep T |wc -l) if [ $TB -ge 1 ]; then T=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/T//g') BYTES=$(echo $T*1024*1024*1024*1024 |bc |awk -F. '{print $1}') - mysql -u root -pmysql -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" + mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" fi diff --git a/diskover-2.1.1.zip b/diskover-2.1.1.zip new file mode 100644 index 0000000..8bf687f Binary files /dev/null and b/diskover-2.1.1.zip differ diff --git a/1forloop.sh b/forloop.sh similarity index 100% rename from 1forloop.sh rename to forloop.sh diff --git a/1function.sh b/function.sh similarity index 92% rename from 1function.sh rename to function.sh index dc12048..48dbf17 100644 --- a/1function.sh +++ b/function.sh @@ -1,10 +1,11 @@ #!/bin/bash #Purpose: Function example. Taking Backup of Particular File #Version:1.0 -#Created Date: Sat May 26 00:27:50 IST 2018 +#Created Date: 2024 Sep 21 #Modified Date: #WebSite: https://arkit.co.in #Author: Ankam Ravi Kumar + # START # function takebackup (){ if [ -f $1 ]; then diff --git a/regex.sh b/regex.sh new file mode 100755 index 0000000..376bb77 --- /dev/null +++ b/regex.sh @@ -0,0 +1,40 @@ +#!/bin/bash +#Purpose: regex examples +#Version: 1.0 +#Create Date: Sun Nov 27 00:27:33 EST 2022 +#Modified Date: + +# START # + +numString1="1234" +numString2="16789" +numString3="1579" + + +echo "Example 1" +if [[ $numString1 =~ ^1 ]]; then + echo "String \"$numString1\" starts with a \"1\", and matches regex: ^1" +fi + +echo "Example 2" +if [[ $numString2 =~ ^1 ]]; then + echo "String \"$numString2\" starts with a \"1\", and matches regex: ^1" +fi + +echo "Example 3" +if [[ $numString3 =~ ^1.7 ]]; then + echo "String \"$numString2\" starts with a \"1\", followed by any character, and followed by a 7. " + echo "This string matches the regex: ^1.7" +fi + +echo "Example 4" +if [[ ! $numString1 =~ ^1.7 ]]; then + echo "String \"$numString1\" does not start with a \"1\", followed by any character, and followed by a 7. " + echo "This string does not match the regex: ^1.7" +fi + +echo "Example 5" +if [[ $numString2 =~ 9$ ]]; then + echo "String \"$numString2\" ends with a \"9\", and matches the regex: 9$" +fi + diff --git a/serverinformation.sh b/serverinformation.sh new file mode 100644 index 0000000..85d4d14 --- /dev/null +++ b/serverinformation.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +mkdir -p /Inventory +sudo chmod -R 777 /Inventory/ +mkdir -p /tmp/asset +touch /tmp/asset/hostname.txt +if [ -f /tmp/asset/hostname.txt ];then + echo "File /tmp/asset/hostname.txt Exists" +else + mkdir /tmp/asset + touch /tmp/asset/hostname.txt +fi +touch /tmp/temptext +TEMP=/tmp/temptext +LOG=`ls /tmp/asset/hostname.txt` +echo "## Host Information" > $LOG +echo "Host Name : `hostname` " >> $LOG +echo "`sudo /sbin/ifconfig -a |grep "inet" | awk 'BEGIN { FS = ":" } ; { print $2 }'`" >> $TEMP +echo "IP Address : `egrep '^10' $TEMP |awk '{ print $1}'`" >> $LOG +echo "IP Address: `hostname -I`" >> $LOG +echo "ip a |grep inet |grep -v "::" |awk '{print $2}'" >> $LOG +echo "iDrac Details: `racadm getniccfg |grep "IP Address" |grep -v "::"`" >> $LOG +echo "Server Type: `servertype=$(lscpu | grep Hypervisor | wc -l); if [ $servertype -gt 0 ]; then echo "VitualMachine"; else echo "Physical"; fi`" >> $LOG +echo -en '\n' >> $LOG + +## Collecting Hardware Details ## +echo " " >> $LOG +echo "## Hardware Information" >> $LOG +echo " " >> $LOG +echo "Serial Number : `sudo lshal |grep system.hardware.serial`" >> $LOG +echo "Serial Number : `sudo /usr/sbin/dmidecode -s system-serial-number`" >> $LOG +echo "Serial Number : `sudo cat /sys/class/dmi/id/product_serial`" >> $LOG +echo "Model Number : `sudo lshal |grep system.hardware.product`" >> $LOG +echo "Model Number : `sudo /usr/sbin/dmidecode |grep "SKU Number"`" >> $LOG +echo "Model Number : `sudo cat /sys/class/dmi/id/product_name`" >> $LOG +echo "Hardware Vendor : `sudo lshal |grep system.hardware.vendor`" >> $LOG +echo "Hardware Vendor : `sudo cat /sys/class/dmi/id/chassis_vendor`" >> $LOG +echo "Hardware Info : `sudo dmesg |grep DMI`" >> $LOG + +## Redhat Version ## +echo " " >> $LOG +echo "## OS Version" >> $LOG +head -n1 /etc/issue >> $LOG +cat /etc/redhat-release >> $LOG +echo "Kernel Version: `uname -r`">> $LOG +echo "OS Version: `hostnamectl | egrep "Operating System" | cut -d ' ' -f5-`" >> $LOG + +## CPU Info ## +echo " " >> $LOG +echo " " >> $LOG +echo "## CPU Information" >> $LOG +grep "model name" /proc/cpuinfo |uniq >> $LOG +COUNTT=$(cat /proc/cpuinfo |grep "model name" | wc -l) +echo "$COUNTT Cores" >> $LOG + +## RAM/MEMORY Info ## +echo " " >> $LOG +echo " " >> $LOG +echo "## Memory Information" >> $LOG +grep MemTotal /proc/meminfo >> $LOG +y=`grep MemTotal /proc/meminfo |awk '{ print $2 }'` +mb="$(( $y / 1024 ))" +gb="$(( $mb / 1024 ))" +echo "RAM : $gb GB" >> $LOG + +## Swap Information ## +echo " " >> $LOG +echo "## Swap Information" >> $LOG +y1=$(free -k |grep Swap |awk '{print $2}') +mb1="$(( $y1 / 1024 ))" +gb1="$(( $mb1 / 1024 ))" +echo "Swap Size: $gb1 GB" >> $LOG + +## Disk Information ## +echo " " >> $LOG +echo "## Disk Information" >> $LOG +lsblk |grep -E 'part|disk' $LOG + +## LVM Information ## +echo " " >> $LOG +echo "## Physical Volumes" >> $LOG +pvs >> $LOG + +echo " " >> $LOG +echo "## Volume Groups" >> $LOG +vgs >> $LOG + +echo " " >> $LOG +echo "## Logical Volumes" >> $LOG +lvs >> $LOG +echo " " >> $LOG + +## Partition Information ## +echo "## DF Command Output" >> $LOG +echo " " >> $LOG +df -Ph -x tmpfs -x devtmpfs| sed s/%//g | awk '{ if($5 > 0) print $0;}' >> $LOG + +echo " " >> $LOG +echo "## Port Information" >> $LOG +ss -alntup |column -t |grep -E 'tcp|udp' >> $LOG + +echo " " >> $LOG +echo "## Service Information" >> $LOG +systemctl list-units --type=service --state=running |grep -vE 'systemd|selinux' >> $LOG + +echo " " >> $LOG +echo "## Docker Containers" >> $LOG +sudo docker ps -a >> $LOG + +echo " " >> $LOG +echo "## DNS Server Details" >> $LOG +cat /etc/resolv.conf >> $LOG + +echo "" >> $LOG +echo "## Server Uptime" >> $LOG +uptime >> $LOG + +sudo cp /tmp/asset/`hostname`.txt /Inventory/`hostname`-`date "+%Y-%m-%d"`.txt diff --git a/useradd_improved.sh b/useradd_improved.sh new file mode 100644 index 0000000..d41a150 --- /dev/null +++ b/useradd_improved.sh @@ -0,0 +1,37 @@ +#!/bin/bash +## Author: Ankam Ravi Kumar +## Date: 21st Sep 2024 +## Purpose: To Create a users in Linux + +check_command_success() { + if [ $? -ne 0 ]; then + echo "Error: $1" + exit 1 + fi +} + +if [ $(id -u) -ne 0 ]; then + echo "Error: Only root may add a user to the system." + exit 2 +fi + +# Prompt for the username and password +read -p "Enter username: " username +read -s -p "Enter password: " password +echo + +if id "$username" &>/dev/null; then + echo "Error: User '$username' already exists!" + exit 1 +fi + +encrypted_password=$(perl -e 'print crypt($ARGV[0], "password")' "$password") +check_command_success "Failed to encrypt the password." + +useradd -m -p "$encrypted_password" "$username" +check_command_success "Failed to add the user." + +passwd -e "$username" +check_command_success "Failed to set password expiry." + +echo "Success: User '$username' has been added to the system!"