/
bash-backup.sh
6387 lines (5463 loc) · 181 KB
/
bash-backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
echo 'Enter the First Number :'
read a
echo 'Enter the Second Number :'
read b
x=$(expr "$a" + "$b")
echo $a + $b = $x
#!/bin/bash
arr=('-' '\' '|' '/')
while true; do
for c in "${arr[@]}"; do
printf "\r %c " $c
sleep .5
done
done
#!/bin/bash
name=$1
path=$2
tar -czvf $name.tar.gz $path
gpg -c $name.tar.gz
rm -rf $name.tar.gz
#!/bin/bash
echo "Enter A Number"
read n
arm=0
temp=$n
while [ $n -ne 0 ]; do
r=$(expr $n % 10)
arm=$(expr $arm + $r \* $r \* $r)
n=$(expr $n / 10)
done
echo $arm
if [ $arm -eq $temp ]; then
echo "Armstrong"
else
echo "Not Armstrong"
fi
#!/bin/bash
echo "Enter a number :"
read Binary
if [ $Binary -eq 0 ]; then
echo "Enter a valid number "
return
else
while [ $Binary -ne 0 ]; do
Bnumber=$Binary
Decimal=0
power=1
while [ $Binary -ne 0 ]; do
rem=$(expr $Binary % 10)
Decimal=$((Decimal + (rem * power)))
power=$((power * 2))
Binary=$(expr $Binary / 10)
done
echo " $Decimal"
done
fi
#!/bin/bash
IP4FW=/sbin/iptables
IP6FW=/sbin/ip6tables
LSPCI=/usr/bin/lspci
ROUTE=/sbin/route
NETSTAT=/bin/netstat
LSB=/usr/bin/lsb_release
## files ##
DNSCLIENT="/etc/resolv.conf"
DRVCONF="/etc/modprobe.conf"
NETALIASCFC="/etc/sysconfig/network-scripts/ifcfg-eth?-range?"
NETCFC="/etc/sysconfig/network-scripts/ifcfg-eth?"
NETSTATICROUTECFC="/etc/sysconfig/network-scripts/route-eth?"
SYSCTL="/etc/sysctl.conf"
## Output file ##
OUTPUT="network.$(date +'%d-%m-%y').info.txt"
## Email info to?? ##
SUPPORT_ID="your_name@service_provider.com"
chk_root() {
local meid=$(id -u)
if [ $meid -ne 0 ]; then
echo "You must be root user to run this tool"
exit 999
fi
}
write_header() {
echo "---------------------------------------------------" >>$OUTPUT
echo "$@" >>$OUTPUT
echo "---------------------------------------------------" >>$OUTPUT
}
dump_info() {
echo "* Hostname: $(hostname)" >$OUTPUT
echo "* Run date and time: $(date)" >>$OUTPUT
write_header "Linux Distro"
echo "Linux kernel: $(uname -mrs)" >>$OUTPUT
$LSB -a >>$OUTPUT
[ -x ${HWINF} ] && write_header "${HWINF}"
[ -x ${HWINF} ] && ${HWINF} >>$OUTPUT
[ -x ${HWINF} ] && write_header "${HWINF}"
[ -x ${HWINF} ] && ${HWINF} >>$OUTPUT
write_header "PCI Devices"
${LSPCI} -v >>$OUTPUT
write_header "$IFCFG Output"
$IFCFG >>$OUTPUT
write_header "Kernel Routing Table"
$ROUTE -n >>$OUTPUT
write_header "Network Card Drivers Configuration $DRVCONF"
[ -f $DRVCONF ] && grep eth $DRVCONF >>$OUTPUT || echo "Error $DRVCONF file not found." >>$OUTPUT
write_header "DNS Client $DNSCLIENT Configuration"
[ -f $DNSCLIENT ] && cat $DNSCLIENT >>$OUTPUT || echo "Error $DNSCLIENT file not found." >>$OUTPUT
write_header "Network Configuration File"
for f in $NETCFC; do
if [ -f $f ]; then
echo "** $f **" >>$OUTPUT
cat $f >>$OUTPUT
else
echo "Error $f not found." >>$OUTPUT
fi
done
write_header "Network Aliase File"
for f in $NETALIASCFC; do
if [ -f $f ]; then
echo "** $f **" >>$OUTPUT
cat $f >>$OUTPUT
else
echo "Error $f not found." >>$OUTPUT
fi
done
write_header "Network Static Routing Configuration"
for f in $NETSTATICROUTECFC; do
if [ -f $f ]; then
echo "** $f **" >>$OUTPUT
cat $f >>$OUTPUT
else
echo "Error $f not found." >>$OUTPUT
fi
done
write_header "IP4 Firewall Configuration"
$IP4FW -L -n >>$OUTPUT
write_header "IP6 Firewall Configuration"
$IP6FW -L -n >>$OUTPUT
write_header "Network Stats"
$NETSTAT -s >>$OUTPUT
write_header "Network Tweaks via $SYSCTL"
[ -f $SYSCTL ] && cat $SYSCTL >>$OUTPUT || echo "Error $SYSCTL not found." >>$OUTPUT
echo "The Network Configuration Info Written To $OUTPUT. Please email this file to $SUPPORT_ID."
}
chk_root
dump_info
#!/bin/bash
DARKGRAY='\033[1;30m'
RED='\033[0;31m'
LIGHTRED='\033[1;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
LIGHTPURPLE='\033[1;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
DEFAULT='\033[0m'
COLORS=($DARKGRAY $RED $LIGHTRED $GREEN $YELLOW $BLUE $PURPLE $LIGHTPURPLE $CYAN $WHITE )
for c in "${COLORS[@]}";do
printf "\r $c LOVE $DEFAULT "
sleep 1
done#!/bin/bash
echo -n "Enter File Name : "
read fileName
if [ ! -f $fileName ]; then
echo "Filename $fileName does not exists"
exit 1
fi
tr '[A-Z]' '[a-z]' <$fileName >>small.txt
#!/usr/bin/env bash
for F in *
do
if [[ -f $F ]]
then
echo $F: $(cat $F | wc -l)
fi
done
MAX=95
EMAIL=server@127.0.0.1
USE=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage ""}')
if [ $USE -gt $MAX ]; then
echo "Percent used: $USE" | mail -s "Running out of CPU power" $EMAIL
fi
#!/bin/bash
printf "0x%x\n" $1
#!/bin/bash
for ((i = 32; i >= 0; i--)); do
r=$((2 ** $i))
Probablity+=($r)
done
[[ $# -eq 0 ]] && {
echo -e "Usage \n \t $0 numbers"
exit 1
}
echo -en "Decimal\t\tBinary\n"
for input_int in $@; do
s=0
test ${#input_int} -gt 11 && {
echo "Support Upto 10 Digit number :: skiping \"$input_int\""
continue
}
printf "%-10s\t" "$input_int"
for n in ${Probablity[@]}; do
if [[ $input_int -lt ${n} ]]; then
[[ $s == 1 ]] && printf "%d" 0
else
printf "%d" 1
s=1
input_int=$(($input_int - ${n}))
fi
done
echo -e
done
#!/bin/bash
echo " Enter your directory: "
read x
du -sh "$x"
MAX=95
EMAIL=server@127.0.0.1
PART=sda1
USE=$(df -h | grep $PART | awk '{ print $5 }' | cut -d'%' -f1)
if [ $USE -gt $MAX ]; then
echo "Percent used: $USE" | mail -s "Running out of disk space" $EMAIL
fi
#!/bin/bash
echo .Enter the First Number: .
read a
echo .Enter the Second Number: .
read b
echo "$a / $b = $(expr $a / $b)"
#!/bin/bash
echo "Welcome, I am ready to encrypt a file/folder for you"
echo "currently I have a limitation, Place me to the same folder, where a file to be encrypted is present"
echo "Enter the Exact File Name with extension"
read file
# decryption command
# gpg -d filename.gpg > filename
gpg -c $file
echo "I have encrypted the file sucessfully..."
echo "Now I will be removing the original file"
rm -rf $file
#!/bin/bash
echo "Enter The Number"
read n
num=$(expr $n % 2)
if [ $num -eq 0 ]; then
echo "is a Even Number"
else
echo "is a Odd Number"
fi
#!/bin/bash
echo "Enter The Number"
read a
fact=1
while [ $a -ne 0 ]; do
fact=$(expr $fact \* $a)
a=$(expr $a - 1)
done
echo $fact
#!/bin/bash
x=0
y=1
i=2
while true ; do
i=$(expr $i + 1)
z=$(expr $x + $y)
echo -n "$z "
x=$y
y=$z
sleep .5
done
#!/usr/bin/env bash
TEMP_FILE=/sys/class/thermal/thermal_zone0/temp
ORIGINAL_TEMP=$(cat $TEMP_FILE)
TEMP_C=$((ORIGINAL_TEMP/1000))
TEMP_F=$(($TEMP_C * 9/5 + 32))
echo $TEMP_F F
#!/usr/bin/env bash
# ------------------------------------------------------------------------ #
# Script Name: hardware_machine.sh
# Description: Show informations about machine hardware.
# Written by: Amaury Souza
# Maintenance: Amaury Souza
# ------------------------------------------------------------------------ #
# Usage:
# $ ./hardware_machine.sh
# ------------------------------------------------------------------------ #
# Bash Version:
# Bash 4.4.19
# ------------------------------------------------------------------------ #
function menuprincipal () {
clear
TIME=1
echo " "
echo $0
echo " "
echo "Choose an option below!
1 - Verify desktop processor
2 - Verify system kernel
3 - Verify installed softwares
4 - Operation system version
5 - Verify desktop memory
6 - Verify serial number
7 - Verify system IP
0 - Exit"
echo " "
echo -n "Chosen option: "
read opcao
case $opcao in
1)
function processador () {
CPU_INFO=`cat /proc/cpuinfo | grep -i "^model name" | cut -d ":" -f2 | sed -n '1p'`
echo "CPU model: $CPU_INFO"
sleep $TIME
}
processador
read -n 1 -p "<Enter> for main menu"
menuprincipal
;;
2)
function kernel () {
#RED HAT: cat /etc/redhat-release
KERNEL_VERSION_UBUNTU=`uname -r`
KERNEL_VERSION_CENTOS=`uname -r`
if [ -f /etc/lsb-release ]
then
echo "kernel version: $KERNEL_VERSION_UBUNTU"
else
echo "kernel version: $KERNEL_VERSION_CENTOS"
fi
}
kernel
read -n 1 -p "<Enter> for main menu"
menuprincipal
;;
3)
function softwares () {
#while true; do
TIME=3
echo " "
echo "Choose an option below for program's list!
1 - List Ubuntu programs
2 - List Fedora programs
3 - Install programs
4 - Back to menu"
echo " "
echo -n "Chosen option: "
read alternative
case $alternative in
1)
echo "Listing all programs Ubuntu's systems..."
sleep $TIME
dpkg -l > /tmp/programs.txt
echo Programs listed and available at /tmp
sleep $TIME
echo " "
echo "Back to menu!" | tr [a-z] [A-Z]
sleep $TIME
;;
2)
echo "Listing all programs Fedora's systems..."
sleep $TIME
yum list installed > /tmp/programs.txt
echo Programs listed and available at /tmp
sleep $TIME
;;
3)
echo Installing programss...
LIST_OF_APPS="pinta brasero gimp vlc inkscape blender filezilla"
#use aptitude command for programs loop.
apt install aptitude -y
aptitude install -y $LIST_OF_APPS
;;
4)
echo Back to main menu...
sleep $TIME
;;
esac
#done
}
softwares
menuprincipal
;;
4)
function sistema () {
VERSION=`cat /etc/os-release | grep -i ^PRETTY`
if [ -f /etc/os-release ]
then
echo "The system version: $VERSION"
else
echo "System not supported"
fi
}
sistema
read -n 1 -p "<Enter> for main menu"
menuprincipal
;;
5)
function memory () {
MEMORY_FREE=`free -m | grep ^Mem | tr -s ' ' | cut -d ' ' -f 4`
#MEMORY_TOTAL=
#MEMORY_USED=
echo Verifying system memory...
echo "Memory free is: $MEMORY_FREE"
}
memory
read -n 1 -p "<Enter> for main menu"
menuprincipal
;;
6)
function serial () {
SERIAL_NUMBER=`dmidecode -t 1 | grep -i serial`
echo $SERIAL_NUMBER
}
serial
read -n 1 -p "<Enter> for main menu"
menuprincipal
;;
7)
function ip () {
IP_SISTEMA=`hostname -I`
echo IP is: $IP_SISTEMA
}
ip
read -n 1 -p "<Enter> for main menu"
menuprincipal
;;
0)
echo Exiting the system...
sleep $TIME
exit 0
;;
*)
echo Invalid option, try again!
;;
esac
}
menuprincipal
#!/bin/bash
echo "Hello World !"
#!/bin/bash
printf "%d \n " $1
#! /bin/bash
echo "Hey what's Your First Name?"
read a
echo "welcome Mr./Mrs. $a, would you like to tell us, Your Last Name"
read b
echo "Thanks Mr./Mrs. $a $b for telling us your name"
echo "*******************"
echo "Mr./Mrs. $b, it's time to say you good bye"
#!/bin/bash
list=($(ls))
for f in "${list[@]}";do
echo $f
done#!/bin/bash
read -p "Enter String Uppercase : " i
o=$(echo "$i" | tr '[:upper:]' '[:lower:]')
echo $o#!/bin/bash
echo .Enter the First Number: .
read a
echo .Enter the Second Number: .
read b
echo "$a * $b = $(expr $a \* $b)"
#!/bin/bash
# A simple shell script to use as a pomodoro app.
# The first argument is the focus time length.
# The second argument is the break length.
# Made by Kiailandi (https://github.com/kiailandi)
wseconds=${1:-25}*60;
pseconds=${2:-wseconds/300}*60;
# Check os and behave accordingly
if [ "$(uname)" == "Darwin" ]; then
while true; do
date1=$((`date +%s` + $wseconds));
while [ "$date1" -ge `date +%s` ]; do
echo -ne "$(date -u -j -f %s $(($date1 - `date +%s`)) +%H:%M:%S)\r";
done
osascript -e 'display notification "Time to walk and rest!" with title "Break"';
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
date2=$((`date +%s` + $pseconds));
while [ "$date2" -gt `date +%s` ]; do
echo -ne "$(date -u -j -f %s $(($date2 - `date +%s`)) +%H:%M:%S)\r";
done
osascript -e 'display notification "Time to get back to work" with title "Work"';
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
done
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
while true; do
date1=$((`date +%s` + $wseconds));
while [ "$date1" -ge `date +%s` ]; do
echo -ne "$(date -u --date @$(($date1 - `date +%s` )) +%H:%M:%S)\r";
done
notify-send "Break" "Time to walk and rest";
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
date2=$((`date +%s` + $pseconds));
while [ "$date2" -ge `date +%s` ]; do
echo -ne "$(date -u --date @$(($date2 - `date +%s` )) +%H:%M:%S)\r";
done
notify-send "Work" "Time to get back to work";
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
done
else
echo -ne "Your OS is currently not supported\n";
fi#!/bin/bash
echo “Enter Any Number”
read n
i=1
c=1
while [ $i -le $n ]; do
i=$(expr $i + 1)
r=$(expr $n % $i)
if [ $r -eq 0 ]; then
c=$(expr $c + 1)
fi
done
if [ $c -eq 2 ]; then
echo “Prime”
else
echo “Not Prime”
fi
#! /bin/bash
echo "Hello $USER"
echo "Hey i am" $USER "and will be telling you about the current processes"
echo "Running processes List"
ps
#!/bin/bash
while true; do
rand=$(shuf -i 2600-2700 -n 1)
echo -n -e ' \u'$rand
sleep 1
done
#!/bin/bash
echo "Hello $USER"
echo "$(uptime)" >>"$(date)".txt
echo "Your File is being saved to $(pwd)"
#!/bin/bash
shuf -i $1-$2 -n 1
#!/bin/bash
# read-menu: a menu driven system information program
clear
echo "
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
"
read -p "Enter selection [0-3] > "
if [[ $REPLY =~ ^[0-3]$ ]]; then
if [[ $REPLY == 0 ]]; then
echo "Program terminated."
exit
fi
if [[ $REPLY == 1 ]]; then
echo "Hostname: $HOSTNAME"
uptime
exit
fi
if [[ $REPLY == 2 ]]; then
df -h
exit
fi
if [[ $REPLY == 3 ]]; then
if [[ $(id -u) -eq 0 ]]; then
echo "Home Space Utilization (All Users)"
du -sh /home/*
else
echo "Home Space Utilization ($USER)"
du -sh $HOME
fi
exit
fi
else
echo "Invalid entry." >&2
exit 1
fi
#!/bin/bash
rsync -avz -e "ssh " /path/to/yourfile user@backupserver.com:/backup/
echo "backup for $(date) " | mail -s "backup complete" user@youremail.com
#!/bin/bash
date
echo "uptime:"
uptime
echo "Currently connected:"
w
echo "--------------------"
echo "Last logins:"
last -a | head -3
echo "--------------------"
echo "Disk and memory usage:"
df -h | xargs | awk '{print "Free/total disk: " $11 " / " $9}'
free -m | xargs | awk '{print "Free/total memory: " $17 " / " $8 " MB"}'
echo "--------------------"
start_log=$(head -1 /var/log/messages | cut -c 1-12)
oom=$(grep -ci kill /var/log/messages)
echo -n "OOM errors since $start_log :" $oom
echo ""
echo "--------------------"
echo "Utilization and most expensive processes:"
top -b | head -3
echo
top -b | head -10 | tail -4
echo "--------------------"
echo "Open TCP ports:"
nmap -p -T4 127.0.0.1
echo "--------------------"
echo "Current connections:"
ss -s
echo "--------------------"
echo "processes:"
ps auxf --width=200
echo "--------------------"
echo "vmstat:"
vmstat 1 5
#! /bin/bash
clear
sum=0
i="y"
echo " Enter one no."
read n1
echo "Enter second no."
read n2
while [ $i = "y" ]; do
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
case $ch in
1)
sum=$(expr $n1 + $n2)
echo "Sum ="$sum
;;
2)
sum=$(expr $n1 - $n2)
echo "Sub = "$sum
;;
3)
sum=$(expr $n1 \* $n2)
echo "Mul = "$sum
;;
4)
sum=$(expr $n1 / $n2)
echo "Div = "$sum
;;
*) echo "Invalid choice" ;;
esac
echo "Do u want to continue (y/n)) ?"
read i
if [ $i != "y" ]; then
exit
fi
done
#!/bin/bash
MAX_NO=0
echo -n "Enter Number between (5 to 9) : "
read MAX_NO
if ! [ $MAX_NO -ge 5 -a $MAX_NO -le 9 ]; then
echo "WTF... I ask to enter number between 5 and 9, Try Again"
exit 1
fi
clear
for ((i = 1; i <= MAX_NO; i++)); do
for ((s = MAX_NO; s >= i; s--)); do
echo -n " "
done
for ((j = 1; j <= i; j++)); do
echo -n " ."
done
echo ""
done
###### Second stage ######################
for ((i = MAX_NO; i >= 1; i--)); do
for ((s = i; s <= MAX_NO; s++)); do
echo -n " "
done
for ((j = 1; j <= i; j++)); do
echo -n " ."
done
echo ""
done
echo -e "\n\n\t\t\t Whenever you need help, Tecmint.com is always there"
#!/bin/bash
echo .Enter the First Number: .
read a
echo .Enter the Second Number: .
read b
x=$(($a - $b))
echo $a - $b = $x
#!/bin/bash
echo .Enter The Number upto which you want to Print Table: .
read n
i=1
while [ $i -ne 10 ]; do
i=$(expr $i + 1)
table=$(expr $i \* $n)
echo $table
done
#!/bin/bash
# test-file: Evaluate the status of a file
echo "Hey what's the File/Directory name (using the absolute path)?"
read FILE
if [ -e "$FILE" ]; then
if [ -f "$FILE" ]; then
echo "$FILE is a regular file."
fi
if [ -d "$FILE" ]; then
echo "$FILE is a directory."
fi
if [ -r "$FILE" ]; then
echo "$FILE is readable."
fi
if [ -w "$FILE" ]; then
echo "$FILE is writable."
fi
if [ -x "$FILE" ]; then
echo "$FILE is executable/searchable."
fi
else
echo "$FILE does not exist"
exit 1
fi
exit
#!/bin/bash
for i in *.jpg; do
convert "$i" -thumbnail 400 "thumbs/$i";
done;
#!/bin/bash
function finish() {
# your cleanup here.
echo "CTL+C pressed"
echo "clean ..."
sleep 1
}
trap finish EXIT
echo 'runing ...'
until false; do
sleep 1
done
#!/bin/bash
LEVEL=$1
for ((i = 0; i < LEVEL; i++)); do
echo $i
CDIR=../$CDIR
done
cd $CDIR
echo "You are in: "$PWD
sh=$(which $SHELL)
exec $sh
#!/bin/bash
VERSION=$1
VERSION2=$2
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
function version_le() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"; }
function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
if version_gt $VERSION $VERSION2; then
echo "$VERSION is greater than $VERSION2"
fi
if version_le $VERSION $VERSION2; then
echo "$VERSION is less than or equal to $VERSION2"
fi
if version_lt $VERSION $VERSION2; then
echo "$VERSION is less than $VERSION2"
fi
if version_ge $VERSION $VERSION2; then
echo "$VERSION is greater than or equal to $VERSION2"
fi
#!/bin/bash
# weather.sh
# Copyright 2018 computer-geek64. All rights reserved.
program=Weather
version=1.1
year=2018
developer=computer-geek64
case $1 in
-h | --help)
echo "$program $version"
echo "Copyright $year $developer. All rights reserved."
echo
echo "Usage: weather [options]"
echo "Option Long Option Description"
echo "-h --help Show the help screen"
echo "-l [location] --location [location] Specifies the location"
;;
-l | --location)
curl https://wttr.in/$2
;;
*)
curl https://wttr.in
;;
esac
#!/bin/bash
# while-menu: a menu driven system information program
DELAY=1 # Number of seconds to display results
while true; do
clear
cat << EOF
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
EOF
read -p "Enter selection [0-3] > "
case "$REPLY" in
0)
break
;;
1)
echo "Hostname: $HOSTNAME"
uptime
;;
2)
df -h
;;
3)
if [[ $(id -u) -eq 0 ]]; then
echo "Home Space Utilization (All Users)"
du -sh /home/*
else
echo "Home Space Utilization ($USER)"
du -sh $HOME
fi
;;
*)
echo "Invalid entry."
;;
esac
sleep "$DELAY"
done
echo "Program terminated."
#!/bin/bash
# while-read: read lines from a file
count=0
while read; do
printf "%d %s\n" $REPLY
count=$(expr $count + 1)
done <$1
#!/bin/bash
#Base Path
basePath='/opt/aws-lambda-adapter/'
logFilePath="$basePath"'deployments/sls-logs/'
mailTemplFile="$basePath"'deployments/mail-template.sh'
#Declaring the variable
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
DARKGRAY="\033[1;90m"
LIGHTBLUE="\033[1;94m"
LIGHTGRAY="\033[1;37m"
NOCOLOR="\033[0m"
#sls config
slsRegion='ap-southeast-1'
slsConfig='serverless.yml'
slsStage=$1
slsProfile=$2
#log file
gitCommitID=$(git log --format="%H" -n 1)
logFile="$logFilePath$gitCommitID"'.log'
#Decorator function
outputDecorator(){
if [ $1 == 0 ]
then
echo -e "${RED}Error: ${NOCOLOR} $2. ${NOCOLOR}" | tee -a $logFile
elif [ $1 == 1 ]
then
echo -e "${GREEN}Success: ${NOCOLOR} $2. ${NOCOLOR}" | tee -a $logFile
elif [ $1 == -1 ]
then
echo -e "$2 ${NOCOLOR}" | tee -a $logFile
fi
}
#Serverless delployment function
serverlessDeployment(){
outputDecorator -1 "${LIGHTBLUE}NPM:${NOCOLOR}${LIGHTGRAY} Installing the App's Dependency Packages...."
npm install
outputDecorator -1 "${LIGHTBLUE}NPM:${NOCOLOR}${LIGHTGRAY} Updating the App's Dependency Packages...."
npm update
outputDecorator -1 "${LIGHTBLUE}SLS:${NOCOLOR}${LIGHTGRAY} Serverless Deploying...."
outputDecorator -1 "${YELLOW} -------------------------------------------------------"
if [ -z "$slsProfile" ]; then
serverless deploy --stage "$slsStage" --region "$slsRegion" | tee -a $logFile
else
serverless deploy --stage "$slsStage" --region "$slsRegion" --profile "$slsProfile" | tee -a $logFile
fi
outputDecorator -1 "${YELLOW} -------------------------------------------------------"
if [ $(grep -o 'Service Information' "$logFile" | wc -l) -gt 0 ]; then
outputDecorator 1 "${GREEN} Serverless Deployment has successfully finished."
else
outputDecorator 1 "${RED} Serverless deploy failed."
fi
}
#Start default OUTPUT line
outputDecorator -1 "${DARKGRAY}############################## DEPLOYMENT LOG ##############################"
#END default line
#Check arguments supplied