diff --git a/AWS/s3bucketsize.sh b/AWS/s3bucketsize.sh new file mode 100644 index 0000000..515783c --- /dev/null +++ b/AWS/s3bucketsize.sh @@ -0,0 +1,18 @@ +#!/bin/bash +#Purpose: To Know S3 Bucket Size Shell Script +#Version:1.0 +#Created Date: 09-Jan-2019 +#Modified Date: +#WebSite: https://www.server-computer.com +#Author: Ankam Ravi Kumar +# START # +echo -e "Please Enter your Bucket Name: \c" +read -r BUCKETNAME +aws s3api list-objects --bucket $BUCKETNAME --output json --query "[sum(Contents[].Size)]" > $PWD/s3bucket +sed -i 's/\[//' $PWD/s3bucket +sed -i 's/]//' $PWD/s3bucket +sed -i 's/ //' $PWD/s3bucket +cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024)" KB"}' +cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024)" MB"}' +cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024/1024)" GB"}' +cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024/1024/1024)" TB"} diff --git a/Arthemetic-Operators.sh b/Arthemetic-Operators.sh index b1c412a..0a29f3f 100644 --- a/Arthemetic-Operators.sh +++ b/Arthemetic-Operators.sh @@ -5,16 +5,17 @@ #Modified Date: #Author: Ankam Ravi Kumar # START # + echo -e "Please enter some value: \c" read -r a echo -e "Please enter another value: \c" read -r b -echo "a+b value is $(($a+$b))" -echo "a-b value is $(($a-$b))" -echo "axb value is $(($a*$b))" -echo "a/b value is $(($a/$b))" -echo "a%b value is $(($a%$b))" +echo "a+b value is $(($a+$b))" #it will add both the values +echo "a-b value is $(($a-$b))" #it will subtract b form a +echo "axb value is $(($a*$b))" #it will multiply both a and b +echo "a/b value is $(($a/$b))" #it will divide b from a +echo "a%b value is $(($a%$b))" #it will give the remainder when a is divided by b echo "Completed successfully" diff --git a/AutomateLoginSSH.sh b/AutomateLoginSSH.sh new file mode 100644 index 0000000..2550268 --- /dev/null +++ b/AutomateLoginSSH.sh @@ -0,0 +1,20 @@ +#!/usr/bin/expect -f +## Testing expect command + +## echo the test +puts "\nGet HostName\n" + +## execute ssh command to connect to remote host +spawn ssh 192.168.175.130 "hostname" + +## Look for password string +expect "password:" + +## Send the password +send "redhat\r" + +puts "\nGet df command output\n" +spawn ssh 192.168.175.130 "df -h" +expect "password:" +send "redhat\r" +interact diff --git a/CpuMemDisk.sh b/CpuMemDisk.sh new file mode 100644 index 0000000..441fe0c --- /dev/null +++ b/CpuMemDisk.sh @@ -0,0 +1,28 @@ +#!/bin/bash +## Collect Multiple Servers CPU, MEM and DISK Utilization and store in single file +# Purpose: To Collect Multiple Servers CPU, MEM, DISK usage in single report +# Version:1.0 +# Created Date: 2019-05-02 +# Modified Date: +# WebSite: https://arkit.co.in +# Author: Ankam Ravi Kumar + +HOSTNAME=$(hostname) +DATET=$(date "+%Y-%m-%d %H:%M:%S") +CPUUSAGE=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}') +MEMUSAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}') +DISKUSAGE=$(df -h / | awk '{print $5}' |tail -n 1 |sed 's/%//g') + +echo 'HostName, Date&Time, CPU(%), MEM(%), DISK(%)' >> /opt/usagereport +echo "$HOSTNAME, $DATET, $CPUUSAGE, $MEMUSAGE, $DISKUSAGE" >> /opt/usagereport + +for i in `cat /scripts/hostlist` +do +RHOST=$(ssh $i hostname) +RDATET=$(ssh $i 'date "+%Y-%m-%d %H:%M:%S"') +RCPUUSAGE=$(ssh $i top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}') +RMEMUSAGE=$(ssh $i free | grep Mem | awk '{print $3/$2 * 100.0}') +RDISKUSAGE=$(ssh $i df -P / |column -t | awk '{print $5}' |tail -n 1 |sed 's/%//g') + +echo "$RHOST, $RDATET, $RCPUUSAGE, $RMEMUSAGE, $RDISKUSAGE" >> /opt/usagereport +done 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 5be4b8d..b718bdf 100644 --- a/arkit.co.in-nested-if.sh +++ b/ExamResults.sh @@ -1,10 +1,11 @@ #!/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 # + echo -e "Please Enter Maths Marks: \c" read -r m echo -e "Please Enter Physics Marks: \c" diff --git a/README.md b/README.md index 63dc105..fff2db0 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,21 @@ -# shell scripting tutorial +# Shell Scripting Tutorial Keep in touch with for any kind of technical questions +[Shell Scripting for Amazon Web Services to Manage it's resources](https://github.com/techtutorials/shell-scripting-tutorial/tree/FOTV/AWS) + https://techtutorials.github.io/shell-scripting-tutorial/ * [Facebook](https://www.facebook.com/Linuxarkit/) * [Email List](https://feedburner.google.com/fb/a/mailverify?uri=arkit) * [Linkedin](https://in.linkedin.com/in/ravi-kumar-94530121) -* [Google Plus](https://plus.google.com/u/0/+RedhatEnterpriseLinuxStepbyStepGuide/posts) * [Twitter](https://twitter.com/aravikumar48) * [Youtube](https://www.youtube.com/Techarkit?sub_confirmation=1) * [Email Address](aravikumar48@gmail.com) +* [WhatsApp Group](http://bit.ly/wappg) +* [Linux Telegram Group](http://bit.ly/linux-telegram) +* [Reddit TechTutorials](http://bit.ly/redditark) +* [Tumblr](https://www.tumblr.com/blog/aravikumar48) A complete begineers guide to learn shell scripting from scratch which includes Videos, Practice scenarios and project idea. I will create one file for one topic with code. @@ -24,143 +29,87 @@ alias and unalias, arch, arp, at, awk, bc, blkid, cal, cat, cd, chage, chattr, c After that start learning shell scripting using below topics -[Shell Scripting Video Tutorial](https://www.youtube.com/watch?v=7GNUzvjS_mE&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu) - -[Shell Scripting course Overview](https://www.youtube.com/watch?v=7GNUzvjS_mE) - -[Linux Basics](https://www.youtube.com/watch?v=IFvMor-0eFM) - -[Linux Directory Structure](https://www.youtube.com/watch?v=rVxpe1_lNFE) - -[Linux Basic Commands](https://www.youtube.com/watch?v=yYC8aaQ3eZA) - -[Copy, Remove, Move and Time Commands](https://www.youtube.com/watch?v=G7XFreQkDB8) - -[Dif and Grep Commands](https://www.youtube.com/watch?v=RwcQ6JzTsmA) - -[Head, tail, sort and more commands](https://www.youtube.com/watch?v=OgV3qrPQulU) - -[tr and wc commands](https://www.youtube.com/watch?v=d40a5zFa8yI) - -[Disk utilities like fdisk, df and du commands](https://www.youtube.com/watch?v=vx1WZepOmKg) - -[Getting Help From Command Line user Interface](https://www.youtube.com/watch?v=GcYu-0IIJas) - -[w, who, hostnamem hostnamectl and uname commands](https://www.youtube.com/watch?v=7shAr5lp_Wc) - -[Search for files and directories using find and locate commands](https://www.youtube.com/watch?v=Rd6e-OrsHpo) - -[top command its output explanation](https://www.youtube.com/watch?v=UQ7rr4_47YY) - -[vi & vim text editor](https://www.youtube.com/watch?v=K3SUrcJ740Y) - -[sed, awk, vmstat and nestat commands](https://www.youtube.com/watch?v=4hJorSKg9E0) - -[vnstat command](https://www.youtube.com/watch?v=KlpE2Ok6Bxo) - -[Introduction to Graphical user interface](https://www.youtube.com/watch?v=Yck_xhz9ku0) - -[cut command](https://www.youtube.com/watch?v=kBZNJdw7RQQ) - -[Merge multiple files using paste command](https://www.youtube.com/watch?v=_Efd6PxhNq4) - -[Connect and Manage remote machine using SSH](https://www.youtube.com/watch?v=Dp9J7aktYDs) - -[Changing files and directory permissions](https://www.youtube.com/watch?v=NNAxqSyTsUI) - -[tar and zip commands](https://www.youtube.com/watch?v=lVQppyhgERA) - -[Scheduling future jobs using crontab](https://www.youtube.com/watch?v=OOOabNTnSwY) - -[difference between scripting and programming](https://www.youtube.com/watch?v=5UuTNosxNgI) - -[what is shell scripting and it's advantages](https://www.youtube.com/watch?v=m2DvuF_S4Ac) - -[PATH environment variable](https://www.youtube.com/watch?v=4TZyWegxzGY) - -[Symbols used shell scripting](https://www.youtube.com/watch?v=L8IxV7bvBHU) - -[Make Shell Script Template](https://www.youtube.com/watch?v=7KEQJ7jtkTg) - -[Quotes single, double and reverse - Know difference between each](https://www.youtube.com/watch?v=9_fhRI-dos4) - -[Bash colors](https://arkit.co.in/coloring-style-text-shell-scripting/) - -[Script exit status](https://arkit.co.in/shell-scripting-exit-status-shell-scripting-return-codes/) - -[Variables and it's rules](https://www.youtube.com/watch?v=839s_OtTqDA) +- [Shell Scripting Video Tutorial](https://www.youtube.com/watch?v=7GNUzvjS_mE&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu) +- [Shell Scripting course Overview](https://www.youtube.com/watch?v=7GNUzvjS_mE) +- [Linux Basics](https://www.youtube.com/watch?v=IFvMor-0eFM) +- [Linux Directory Structure](https://www.youtube.com/watch?v=rVxpe1_lNFE) +- [Linux Basic Commands](https://www.youtube.com/watch?v=yYC8aaQ3eZA) +- [Copy, Remove, Move and Time Commands](https://www.youtube.com/watch?v=G7XFreQkDB8) +- [Dif and Grep Commands](https://www.youtube.com/watch?v=RwcQ6JzTsmA) +- [Head, tail, sort and more commands](https://www.youtube.com/watch?v=OgV3qrPQulU) +- [tr and wc commands](https://www.youtube.com/watch?v=d40a5zFa8yI) +- [Disk utilities like fdisk, df and du commands](https://www.youtube.com/watch?v=vx1WZepOmKg) +- [Getting Help From Command Line user Interface](https://www.youtube.com/watch?v=GcYu-0IIJas) +- [w, who, hostnamem hostnamectl and uname commands](https://www.youtube.com/watch?v=7shAr5lp_Wc) +- [Search for files and directories using find and locate commands](https://www.youtube.com/watch?v=Rd6e-OrsHpo) +- [top command its output explanation](https://www.youtube.com/watch?v=UQ7rr4_47YY) +- [vi & vim text editor](https://www.youtube.com/watch?v=K3SUrcJ740Y) +- [sed, awk, vmstat and nestat commands](https://www.youtube.com/watch?v=4hJorSKg9E0) +- [vnstat command](https://www.youtube.com/watch?v=KlpE2Ok6Bxo) +- [Introduction to Graphical user interface](https://www.youtube.com/watch?v=Yck_xhz9ku0) +- [cut command](https://www.youtube.com/watch?v=kBZNJdw7RQQ) +- [Merge multiple files using paste command](https://www.youtube.com/watch?v=_Efd6PxhNq4) +- [Connect and Manage remote machine using SSH](https://www.youtube.com/watch?v=Dp9J7aktYDs) +- [Changing files and directory permissions](https://www.youtube.com/watch?v=NNAxqSyTsUI) +- [tar and zip commands](https://www.youtube.com/watch?v=lVQppyhgERA) +- [Scheduling future jobs using crontab](https://www.youtube.com/watch?v=OOOabNTnSwY) +- [difference between scripting and programming](https://www.youtube.com/watch?v=5UuTNosxNgI) +- [what is shell scripting and it's advantages](https://www.youtube.com/watch?v=m2DvuF_S4Ac) +- [PATH environment variable](https://www.youtube.com/watch?v=4TZyWegxzGY) +- [Symbols used shell scripting](https://www.youtube.com/watch?v=L8IxV7bvBHU) +- [Make Shell Script Template](https://www.youtube.com/watch?v=7KEQJ7jtkTg) +- [Quotes single, double and reverse - Know difference between each](https://www.youtube.com/watch?v=9_fhRI-dos4) +- [Bash colors](https://arkit.co.in/coloring-style-text-shell-scripting/) +- [Script exit status](https://arkit.co.in/shell-scripting-exit-status-shell-scripting-return-codes/) +- [Variables and it's rules](https://www.youtube.com/watch?v=839s_OtTqDA) +- [Special Variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) +- [Environment Variables, system variables and user defined variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) +- [Constant variables, Local & Global variables and Special variables](https://www.youtube.com/watch?v=839s_OtTqDA) +- [Positional Parameters](https://www.youtube.com/watch?v=PfxzX4XNYRE) +- [Count number command line arguments $#](https://www.youtube.com/watch?v=YizjrX9ph10) +- [Arithmetic Operators](https://www.youtube.com/watch?v=qxNQ_D8txPo) +- [Relational Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) +- [LogicalOperators](https://www.youtube.com/watch?v=m_F1FTKdUU4) +- [Boolean Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) +- [Maths using expr command](https://www.youtube.com/watch?v=qxNQ_D8txPo) +- [Real maths using bc command](https://www.youtube.com/watch?v=qxNQ_D8txPo) +- [if statement](https://www.youtube.com/watch?v=gncu9vzmILw) +- [if-else statement](https://www.youtube.com/watch?v=nDhbOeEQeNY) +- [if-else-if statement](https://www.youtube.com/watch?v=UJET-9cmaqU) +- [Nested if statement](https://www.youtube.com/watch?v=Kd1SJFnmj9k) +- [Case statement](https://www.youtube.com/watch?v=JJ7mAPU0KhI) +- [For Loop](https://www.youtube.com/watch?v=1fnAUUS4qg0) +- [While Loop](https://www.youtube.com/watch?v=nBMuVIRGpwY) +- [Until Loop](https://www.youtube.com/watch?v=zdk795qFgWk) +- [Functions](https://www.youtube.com/watch?v=jXv1otUXMG4) +- [Arrays](https://www.youtube.com/watch?v=2Fetj2V6rrM) +- [Eval command](https://www.youtube.com/watch?v=AjqBRGwLmLc&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu&index=57&t=0s) +- [Shifting parameters using shift command](https://www.youtube.com/watch?v=48j0kxOFKZE) +- [IFS - Input Field Separator](https://www.youtube.com/watch?v=so8IRuhWjEM) +- [Writing CPU Usage script](https://www.youtube.com/watch?v=NQx43bY4lNo) +- [Writing Disk Utilization script](https://www.youtube.com/watch?v=yXhdDV13nrA) +- [Trouble shooting debugging shell scripts](https://www.youtube.com/watch?v=kgj-4_gmvi4) +- [Checking shell script errors and improvements using shellcheck.net site](https://www.youtube.com/watch?v=kgj-4_gmvi4) +- [Here Document to write paragraphs of text](https://www.youtube.com/watch?v=r9lb0ZxGFqE) +- [Getopts Function](https://www.youtube.com/watch?v=j-lEoC0DWI8) +- [Executing Multiple scripts from single script](https://youtu.be/hs-FK681D50) +- [logger logging messages to log file](https://youtu.be/_kMXvtn1RRQ) -[Special Variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) - -[Environment Variables, system variables and user defined variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) - -[Constant variables, Local & Global variables and Special variables](https://www.youtube.com/watch?v=839s_OtTqDA) - -[Positional Parameters](https://www.youtube.com/watch?v=PfxzX4XNYRE) - -[Count number command line arguments $#](https://www.youtube.com/watch?v=YizjrX9ph10) - -[Arithmetic Operators](https://www.youtube.com/watch?v=qxNQ_D8txPo) - -[Relational Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) - -[LogicalOperators](https://www.youtube.com/watch?v=m_F1FTKdUU4) - -[Boolean Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) - -[Maths using expr command](https://www.youtube.com/watch?v=qxNQ_D8txPo) - -[Real maths using bc command](https://www.youtube.com/watch?v=qxNQ_D8txPo) - -[if statement](https://www.youtube.com/watch?v=gncu9vzmILw) - -[if-else statement](https://www.youtube.com/watch?v=nDhbOeEQeNY) - -[if-else-if statement](https://www.youtube.com/watch?v=UJET-9cmaqU) - -[Nested if statement](https://www.youtube.com/watch?v=Kd1SJFnmj9k) - -[Case statement](https://www.youtube.com/watch?v=JJ7mAPU0KhI) - -[For Loop](https://www.youtube.com/watch?v=1fnAUUS4qg0) - -[While Loop](https://www.youtube.com/watch?v=nBMuVIRGpwY) - -[Until Loop](https://www.youtube.com/watch?v=zdk795qFgWk) - -[Functions](https://www.youtube.com/watch?v=jXv1otUXMG4) - -[Arrays](https://www.youtube.com/watch?v=2Fetj2V6rrM) - -[Eval command](https://www.youtube.com/watch?v=AjqBRGwLmLc&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu&index=57&t=0s) - -[Shifting parameters using shift command](https://www.youtube.com/watch?v=48j0kxOFKZE) - -[IFS - Input Field Separator](https://www.youtube.com/watch?v=so8IRuhWjEM) - -[Writing CPU Usage script](https://www.youtube.com/watch?v=NQx43bY4lNo) - -[Writing Disk Utilization script](https://www.youtube.com/watch?v=yXhdDV13nrA) - -[Trouble shooting debugging shell scripts](https://www.youtube.com/watch?v=kgj-4_gmvi4) - -[Checking shell script errors and improvements using shellcheck.net site](https://www.youtube.com/watch?v=kgj-4_gmvi4) - -[Here Document to write paragraphs of text](https://www.youtube.com/watch?v=r9lb0ZxGFqE) - -[Getopts Function](https://www.youtube.com/watch?v=j-lEoC0DWI8) - -[Executing Multiple scripts from single script](https://youtu.be/hs-FK681D50) +**Resource to Download** -[logger logging messages to log file](https://youtu.be/_kMXvtn1RRQ) +- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile48/) +- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_pack42/) +- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_advb01/) +- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile54/) -**Resource to Download** +**Write Your Own Method of Script for below Scenario** -[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile48/) +- **Scenario:** Everyday from Monday to Friday one directory will be created under /fullbackup/dailybackup/YYYY-MM-DD and it will move backup to its parent directory everyday midnight /fullbackup/archive/, However Saturday, Sunday and Monday directories will move to /fullbackup/archive path every monday evening. -[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_pack42/) +- **Directory Names Example:** 2018-12-24 2018-12-25 2018-12-26 2018-12-27 2018-12-28 -[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_advb01/) +- **Question:** I would like to delete directories older than two days from /fullbackup/archive path. How do you do it using any scripting methods. -[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile54/) +- **Problem Statement:** I was trying to use ```find /path/ -type d -mtime +2 -print0 | xargs -r0 rm --```. This command does not work as expected due to directory modified date for SAT, SUN and MON moved directories same for all as Monday date. +- **How Do you solve it.??** Write Shell Script to accomplish this task. Should run through crontab and clear directories older than two days. diff --git a/add.sh b/add.sh index b6dec80..8909fed 100644 --- a/add.sh +++ b/add.sh @@ -1,10 +1,12 @@ #!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar +################################################## +# Purpose: eval command Evaluating twice +# Version:1.0 +# Created Date: Wed Jun 13 22:09:59 IST 2018 +# Modified Date: +# WebSite: https://arkit.co.in +# Author: Ankam Ravi Kumar +################################################## # START # echo "addition of X+Y" @@ -14,4 +16,4 @@ echo "Enter Y" read Y echo "X+Y = $X+$Y = $[ X+Y ]" -# END # \ No newline at end of file +# END # diff --git a/agtb.sh b/agtb.sh index ac23317..0a67093 100644 --- a/agtb.sh +++ b/agtb.sh @@ -7,14 +7,14 @@ #Author: Ankam Ravi Kumar # START # -echo "enter the a vloue $a" +echo -e "enter the a value: \c" read a -echo "enter the b volue $b" +echo -e "enter the b value: \c" read b if test "$a" -gt "$b" ; then echo "$a is greater than $b" else -echo "$b is greater than $a" + echo "$b is greater than $a" fi # END # \ No newline at end of file diff --git a/answers.sh b/answers.sh new file mode 100644 index 0000000..697f19b --- /dev/null +++ b/answers.sh @@ -0,0 +1,15 @@ +#!/usr/bin/expect + +set timeout -1 + +spawn ./questions.sh +expect "Hi\r" +send -- "Hi\r" + +expect "How are you?\r" +send -- "I am fine\r" + +expect "Whats your Name?\r" +send -- "My name is Ravi\r" + +expect eof diff --git a/array.sh b/array.sh index ca7d6f8..7c61603 100644 --- a/array.sh +++ b/array.sh @@ -6,6 +6,7 @@ #WebSite: https://arkit.co.in #Author: Ankam Ravi Kumar # START # + fruits=( "Apple" "Orange" "Banana" "Sapota" ) fruits[3]='Green Apple' for fruit in ${fruits[@]} diff --git a/casestatement.sh b/casestatement.sh index 149c6f2..e68b229 100644 --- a/casestatement.sh +++ b/casestatement.sh @@ -6,9 +6,9 @@ #Modified Date: #Author: Ankam Ravi Kumar # START # -echo -c "Enter a number: \c" +echo -e "Enter a number: \c" read -r a -echo -c "Enter b number: \c" +echo -e "Enter b number: \c" read -r b echo "1. Sum of values" @@ -16,7 +16,7 @@ echo "2. Substraction" echo "3. Multiplication" echo "4. Division" echo "5. Modulo division" -echo -c "Enter Your Choice from above menu: \c" +echo -e "Enter Your Choice from above menu: \c" read -r ch case $ch in 1) echo "Sum of $a + $b = "`expr $a + $b`;; diff --git a/collectroothistory.sh b/collectroothistory.sh new file mode 100644 index 0000000..6e0c9e1 --- /dev/null +++ b/collectroothistory.sh @@ -0,0 +1,26 @@ +#!/bin/bash +## Collect Root Commands History + +# Mailing List +MAILLIST="YOUREMAIL@DOMAIN" + +# Log path +AUDLOG="/rootcommands" + +cp /root/.bash_history /tmp/history +sed -i 's/#//g' /tmp/history +for i in `cat /tmp/history |grep ^[0-9]` +do +CONVT=`date -d @$i` +sed -i "s/$i/$CONVT/g" /tmp/history +done + +sed -i 'N;s/\n/ /' /tmp/history +sleep 10 + +/bin/touch ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` +/bin/grep "$DATE" /tmp/history > ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` +/bin/chmod 0440 ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` + +# Mail notification +/bin/cat ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` |mail -s "HOST: $HOSTNAME - `whoami` Daily root Commands Log" ${MAILLIST} diff --git a/convert_and_update_mysql.sh b/convert_and_update_mysql.sh new file mode 100644 index 0000000..98f4d25 --- /dev/null +++ b/convert_and_update_mysql.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +n=1 +until [ $n -gt 11196 ] +do +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}') + +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 -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 -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 -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 -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" + fi + + +n=`expr "$n" + 1` + +done diff --git a/countargs.sh b/countargs.sh index 8b63dc5..e25e305 100644 --- a/countargs.sh +++ b/countargs.sh @@ -1,15 +1,17 @@ #!/bin/bash -#Purpose: Counting given postional parameters. -#Version:1.0 -#Created Date: Mon May 7 21:55:05 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar +################################################## +# Purpose: Counting given postional parameters. +# Version:1.0 +# Created Date: Mon May 7 21:55:05 IST 2018 +# Modified Date: +# Author: Ankam Ravi Kumar +################################################## + # START # -#echo "Your current given parameters are $#" +echo "Your current given parameters are $#" if [ $# -lt 1 ];then echo "Program Usage is './scriptname.sh' options" else echo "Program executed successfully" fi - # END # diff --git a/details.sh b/details.sh index 8a64338..cf701a3 100644 --- a/details.sh +++ b/details.sh @@ -7,7 +7,7 @@ #Author: Ankam Ravi Kumar # START # -echo "WEL COME TO $USER" +echo "WEL COME TO $USERNAME" echo "Your present working directory is `pwd`" echo "current logged in users are `who`" echo "Today date is `date`" 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/for-loop.sh b/for-loop.sh index d399c5f..d431716 100644 --- a/for-loop.sh +++ b/for-loop.sh @@ -6,14 +6,14 @@ #Modified Date: #Author: Ankam Ravi Kumar # START # -for i in `cat hostfile` +for server in `cat /scripts/servers` do -ping -c 1 $i > /tmp/pingresults +ping -c 1 $server > /tmp/ping valid=`echo $?` -if [ $valid -gt 1 ]; then -echo "$i Host is not reachable" +if [ $valid -eq 0 ]; then +echo "$server is up" else -echo "$i Host is Up" +echo "$server is Down" fi done # END # 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/generate_win_host_config.sh b/generate_win_host_config.sh new file mode 100644 index 0000000..cc6259e --- /dev/null +++ b/generate_win_host_config.sh @@ -0,0 +1,24 @@ +#!/bin/bash +## Purpose: To Generate Nagios Configuration files within minute of time. +## Author: Ankam Ravi Kumar + +mkdir -p /scripts/WinServers +cat /scripts/serverlist.txt | while read LINE +do + HostIP=`echo $LINE | cut -d, -f1` + HostName=`echo $LINE | cut -d, -f2` + +NSCLIENTSTATE=$(/usr/local/nagios/libexec/check_nt -H $HostIP -p 12489 -v CLIENTVERSION -s Password | echo $?) +if [ $NSCLIENTSTATE -eq 0 ]; then + sed -e "s/XXXX/$HostName/g; s/ZZZZ/$HostIP/g" /scripts/Template-Windows.cfg > /scripts/WinServers/$HostName.cfg + +for i in D E F G H I J K L M N O P Q R S T U V W X Y Z; +do +/usr/local/nagios/libexec/check_nt -H $HostIP -p 12489 -v USEDDISKSPACE -s Password -l $i -w 90 -c 95 +COMMANDSTATUS=$(echo $?) +if [ $COMMANDSTATUS -eq 0 ] || [ $COMMANDSTATUS -eq 2 ];then +sed -e "s/XXXX/$HostName/g; s/ZZZZ/$i/g" /scripts/Drives.cfg >> /scripts/WinServers/$HostName.cfg +fi +done +fi +done diff --git a/hi.sh b/hi.sh index b0365ef..6652c64 100644 --- a/hi.sh +++ b/hi.sh @@ -9,13 +9,13 @@ tmp=`date | cut -c12-13` if [ $tmp -lt 11 ] ; then -echo "Good Mornind have a nice day $USER" +echo "Good Mornind have a nice day $USERNAME" elif [ $tmp -gt 11 -a $tmp -lt 16 ] ; then -echo "Good Ofter noon $USER" +echo "Good Ofter noon $USERNAME" elif [ $tmp -gt 15 -a $tmp -lt 19 ] ; then -echo "Good Evening $USER" +echo "Good Evening $USERNAME" else -echo "Good Night Sweet dreams $USER" +echo "Good Night Sweet dreams $USERNAME" fi echo "Now the time is `date |cut -c12-19`" diff --git a/if-elif-if.sh b/if-elif-if.sh index ee2e09b..da88e28 100644 --- a/if-elif-if.sh +++ b/if-elif-if.sh @@ -5,6 +5,7 @@ #Modified Date: #Author: Ankam Ravi Kumar # START # + echo -e "Please Enter a Value: \c" read -r a echo -e "Please Enter b Value: \c" diff --git a/if-else-statement.sh b/if-else-statement.sh index 1393446..7e5b04f 100644 --- a/if-else-statement.sh +++ b/if-else-statement.sh @@ -6,7 +6,7 @@ #Website: https://arkit.co.in #Author: Ankam Ravi Kumar # START # -echo -e "Enter any value> \c" +echo -e "Enter any value: \c" read -r a echo -e "Enter any value: \c" read -r b diff --git a/info.sh b/info.sh index b32785c..caac61a 100644 --- a/info.sh +++ b/info.sh @@ -10,8 +10,8 @@ echo "Hi you there" echo "what is your name? (Type your name here and press Enter)" read NM -echo "Hi $NM Good Morning" -echo "your currently logged in as $USER" +echo "Hi $NM Good Morning" +echo "your currently logged in as $USERNAME" echo "your present working directory is `pwd`" # END # diff --git a/memusage.sh b/memusage.sh new file mode 100644 index 0000000..45187ca --- /dev/null +++ b/memusage.sh @@ -0,0 +1,18 @@ +#!/bin/bash +## Monitoring Memory usage of the server +# Version:1.0 +# Created Date: 2022-Jan-07 +# WebSite: https://arkit.co.in +# Author: Ankam Ravi Kumar + +HOSTNAME=$(hostname) +DATED=$(date "+%Y-%m-%d %H:%M:%S") +THRESHOLD=80 +TOADDRESS=aravikumar48@gmail.com + +MEMUSAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}' |awk -F. '{print $1}') +if [ $MEMUSAGE -ge $THRESHOLD ]; then +echo "$HOSTNAME, $DATED, %MEMUSAGE" >> /var/log/memusage_history +echo "$HOSTNAME, $DATED, %MEMUSAGE" > /tmp/memusage +mail -s "$HOSTNAME $DATED Mem Usage: $MEMUSAGE" $TOADDRESS <<< /tmp/memusage +fi diff --git a/morethanxdays.sh b/morethanxdays.sh new file mode 100644 index 0000000..2a89a07 --- /dev/null +++ b/morethanxdays.sh @@ -0,0 +1,14 @@ +#!/bin/bash +## Delete the Directories older than 2 days based on directory name validation +## Refer YouTube Link for Explanation https://youtu.be/1Sh6PWcgXAA +ls -ltr /fullbackup/archive/ | awk '{print $9}' > /scripts/dirs +for i in `cat /scripts/dirs`; do +STARTTIME=$(date +%s -d"$i 00:00:00") +ENDTIME=$(date +%s) +echo $((ENDTIME-STARTTIME)) | awk '{print int($1/60)}' > /scripts/value +COUNT=`cat /scripts/value` +if [ $COUNT -gt 2880 ]; then +echo "Directories are older than 2days $i" >> /scripts/joblog +rm -rf /fullbackup/archive/$i +fi +done diff --git a/myfirstscript.sh b/myfirstscript.sh index ad53bc9..2c39c40 100644 --- a/myfirstscript.sh +++ b/myfirstscript.sh @@ -7,7 +7,7 @@ #Modified by: # START -echo "Welcome $USER" +echo "Welcome $USERNAME" echo "Your present working directory is `pwd`" echo "Today date is `date`" # END diff --git a/nestedif.sh b/nestedif.sh index 5be4b8d..17d421b 100644 --- a/nestedif.sh +++ b/nestedif.sh @@ -5,6 +5,7 @@ #Modified Date: #Author: Ankam Ravi Kumar # START # + echo -e "Please Enter Maths Marks: \c" read -r m echo -e "Please Enter Physics Marks: \c" diff --git a/or-operator.sh b/or-operator.sh index 5a66bd7..2931df0 100644 --- a/or-operator.sh +++ b/or-operator.sh @@ -5,7 +5,8 @@ #Modified Date: #Author: Ankam Ravi Kumar # START # -echo -e "Enter First Numberic Value: \c" + +echo -e "Enter First Numeric Value: \c" read -r t echo -e "Enter Second Numeric Value: \c" read -r b @@ -13,7 +14,7 @@ read -r b if [ $t -le 20 -o $b -ge 30 ]; then echo "Statement is True" else -echo "Flase, Statement Try Again." +echo "False Statement, Try Again." fi # END # diff --git a/questions.sh b/questions.sh new file mode 100644 index 0000000..c93a791 --- /dev/null +++ b/questions.sh @@ -0,0 +1,11 @@ +#!/bin/bash +## Questions + +echo "Hi" +read $REPLY + +echo "How are you?" +read $REPLY + +echo "Whats your Name?" +read $REPLY 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/remoteload.sh b/remoteload.sh new file mode 100644 index 0000000..83da24b --- /dev/null +++ b/remoteload.sh @@ -0,0 +1,20 @@ +#!/bin/bash +################################################## +# # +# Author: Ankam Ravi Kumar # +# Website: server-computer.com # +# Date: 23-02-2019 16:59:56 # +# Purpose: Capture and Store System Load Average # +# CPU Usage and Memory Usage # +################################################## +# Log File Path +LOGFILE=/var/log/systemload.log + +echo "" > /tmp/remotelog + +for i in `cat /opt/hostnames`; +do +cat /root/systemload.sh | ssh $i >> /tmp/remotelog +done + +cat /tmp/remotelog |grep -vE "^Last|^There" >> $LOGFILE 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/systemload.sh b/systemload.sh new file mode 100644 index 0000000..3f7d663 --- /dev/null +++ b/systemload.sh @@ -0,0 +1,19 @@ +#!/bin/bash +################################################## +# # +# Author: Ankam Ravi Kumar # +# Website: server-computer.com # +# Date: 23-02-2019 16:59:56 # +# Purpose: Capture and Store System Load Average # +# CPU Usage and Memory Usage # +################################################## +# Log File Path +LOGFILE=/var/log/systemload.log + +HOSTNAME=$(hostname) +DATE=$(date "+%d-%m-%Y %H:%M:%S") +SYSTEMLOAD=$(uptime | awk '{ print $8,$9,$10,$11,$12}') +CPULOAD=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 |awk '{print $2}') +MEMORYUSAGE=$(free -m |grep Mem: |tail -n1 |awk '{print $2,$3}') + +echo "$DATE $HOSTNAME LoadAverage: $SYSTEMLOAD CPU: $CPULOAD Memory: $MEMORYUSAGE" >> $LOGFILE 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!" diff --git a/userexists.sh b/userexists.sh new file mode 100644 index 0000000..1b8dde7 --- /dev/null +++ b/userexists.sh @@ -0,0 +1,18 @@ +#!/bin/bash +##Purpose: Check given user Exits Or Not +##Date: 27th Oct 2016 +##Author: Ankam Ravi Kumar +##WebSite: https://arkit.co.in + +##Start +echo -e "Please Enter User name you want check: \c" +read user +grep $user /etc/passwd > /dev/null +if [ $? -eq 0 ]; then +grep $user /etc/passwd +echo "$user Exists in this Machine" +else +echo "$user does not exists" +fi + +##END diff --git a/variables.sh b/variables.sh index 7d765aa..7f3128d 100644 --- a/variables.sh +++ b/variables.sh @@ -6,6 +6,7 @@ #website: https://arkit.co.in #Author: Ankam Ravi Kumar # START # + A=10 Ba=23 BA=45 diff --git a/webserver_ubuntu.sh b/webserver_ubuntu.sh new file mode 100755 index 0000000..6a28ea9 --- /dev/null +++ b/webserver_ubuntu.sh @@ -0,0 +1,142 @@ +#!/usr/bin/env bash + +############################################################# +# # +# NOME: webserver_ubuntu.sh # +# # +# AUTOR: Amaury B. Souza (amaurybsouza@gmail.com) # +# # +# DESCRIÇÃO: O script faz a instalação da stack LAMP # +# # +# USO: ./webserver_ubuntu.sh # +############################################################# + +function menuprincipal () { + clear + echo " " + echo LAMP Stack Ubuntu $0 + echo " " + echo "Escolha uma opção abaixo para começar! + + 1 - Instalar Apache no sistema + 2 - Instalar o banco de dados MariaDB no sistema + 3 - Instalar o PHP7.2 no sistema + 4 - Instalar a stack LAMP completa no sistema + 0 - Sair do menu de instalação" +echo " " +echo -n "Opção escolhida: " +read opcao +case $opcao in + 1) + function apache () { + TIME=2 + echo Atualizando seu sistema... + sleep $TIME + apt update && apt upgrade -y + echo Iniciando a instalação do Apache no Ubuntu... + sleep $TIME + #sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT + #sudo ufw allow http + #sudo chown www-data:www-data /var/www/html/ -R + apt install -y apache2 apache2-utils + sudo systemctl start apache2 + sudo systemctl enable apache2 + echo " " + if [ $? -eq 0 ] + then + echo O Apache foi instalado no seu sistema. + else + echo Ops, ocorreu algum erro, vamos tentar de novo! + fi + } + apache + read -n 1 -p " para menu principal" + menuprincipal + ;; + + 2) + function maria () { + TIME=2 + echo Iniciando a instalação do MariaDB... + sleep $TIME + sudo apt -y install mariadb-server mariadb-client + sudo systemctl start mariadb + sudo systemctl enable mariadb + if [ $? -eq 0 ] + then + echo Agora vamos configurar o banco... + sleep $TIME + sudo mysql_secure_installation + echo " " + echo Opa, parabéns, o banco foi instalado e configurado! + sleep $TIME + else + echo Ops, vamos resolver isso? Acho que deu errado. + fi + } + maria + read -n 1 -p " para menu principal" + menuprincipal + ;; + + 3) + function php () { + echo Iniciando a instalação do PHP... + sudo apt install -y php7.2 libapache2-mod-php7.2 php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline + sudo a2enmod php7.2 + sudo systemctl restart apache2 + echo " " + echo O PHP 7.2 foi instalado, que legal! + #Para testar o PHP instalado... + #sudo vim /var/www/html/info.php + } + php + read -n 1 -p " para menu principal" + menuprincipal + ;; + + 4) + function lamp () { + TIME=2 + #apache + echo Vamos iniciar a instalação da stack LAMP no seu sistema... + sleep $TIME + echo Instalando o Apache... + sleep $TIME + apt install -y apache2 apache2-utils + sudo systemctl start apache2 + sudo systemctl enable apache2 + echo Instalando o banco de dados... + sleep $TIME + #banco de dados + sudo apt -y install mariadb-server mariadb-client + sudo systemctl start mariadb + sudo systemctl enable mariadb + #PHP + echo Instalando o PHP... + sleep $TIME + sudo apt install -y php7.2 libapache2-mod-php7.2 php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline + sudo a2enmod php7.2 + sudo systemctl restart apache2 + echo Instalação concluída com êxito! + sleep $TIME + } + lamp + read -n 1 -p " para menu principal" + menuprincipal + ;; + + 0) + function sair () { + TIME=2 + echo " " + echo Saindo do sistema... + sleep $TIME + exit 0 + } + sair + ;; + +esac +} +menuprincipal diff --git a/while-loop.sh b/while-loop.sh index b636866..3f314c7 100644 --- a/while-loop.sh +++ b/while-loop.sh @@ -1,8 +1,10 @@ -While Loop Example, print any given number table. - #!/bin/bash -## While Loop Example with 2 table -echo -e "Please provide one value:\c" +# While Loop Example with 2 table, print any given number table. +# See Full Explanation of this above shell script [while loop](https://www.youtube.com/Techarkit?sub_confirmation=1) + +#START + +echo -e "Please provide one value: \c" read -r c i=1 while [ $i -le 10 ] @@ -12,4 +14,4 @@ echo "$c * $i = $b" i=`expr $i + 1` done -See Full Explanation of this above shell script [while loop](https://www.youtube.com/Techarkit?sub_confirmation=1) +#END \ No newline at end of file