Skip to content

Commit 067ef34

Browse files
authored
Merge pull request #12 from tainguyenbp/feat/learn-update-script-check-linux
Create readme.md
2 parents 1a0525d + f026fef commit 067ef34

File tree

9 files changed

+164
-0
lines changed

9 files changed

+164
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
year_global=$(date +"%Y")
6+
month_global=$(date +"%m")
7+
day_global=$(date +"%d")
8+
ymd_global=$year_global$month_global$day_global
9+
10+
name_file_log="file-large-size-"$ymd_global".log"
11+
12+
path_file_log=""$CURRENT_DIR"/"$name_file_log""
13+
path_find_file='/'
14+
file_size='+10M'
15+
head='-500'
16+
string_remove_grep='grep -v \"/var/lib/mysql|/srv/minio|postgresql\"'
17+
18+
function _remove_log_find_file() {
19+
20+
for i in `seq 10 20`; do
21+
year_ago=$(date -d "$i days ago" +"%Y")
22+
month_ago=$(date -d "$i days ago" +"%m")
23+
day_ago=$(date -d "$i days ago" +"%d")
24+
ymd_ago=$year_ago$month_ago$day_ago
25+
rm -rf "$path_file_log"/_"$ymd_ago"
26+
done
27+
}
28+
29+
function _report_find_file_large() {
30+
31+
find $path_find_file -xdev -type f -size $file_size -exec du -sh {} ';'| sort -rh | head $head | $string_remove_grep >> $path_file_log &
32+
33+
}
34+
35+
_report_find_file_large
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# find file large linux and report to file log
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
year_global=$(date +"%Y")
6+
month_global=$(date +"%m")
7+
day_global=$(date +"%d")
8+
ymd_global=$year_global$month_global$day_global
9+
10+
name_file_log="log-inode-system-"$ymd_global".log"
11+
path_file_log=""$CURRENT_DIR"/"$name_file_log""
12+
13+
echo "" > $path_file_log
14+
path_find_inode='/home/*'
15+
16+
function _remove_log_find_file() {
17+
18+
for i in `seq 10 20`; do
19+
year_ago=$(date -d "$i days ago" +"%Y")
20+
month_ago=$(date -d "$i days ago" +"%m")
21+
day_ago=$(date -d "$i days ago" +"%d")
22+
ymd_ago=$year_ago$month_ago$day_ago
23+
rm -rf "$path_file_log"/_"$ymd_ago"
24+
done
25+
}
26+
27+
function _report_find_inode_system(){
28+
29+
echo "Path Directory Find Inode System: $path_find_inode"
30+
echo "Path Directory Find Inode System: $path_find_inode" >> $path_file_log
31+
for directory_path in $path_find_inode;
32+
do result_find_inode=$(find $directory_path | wc -l);
33+
printf "$result_find_inode\t\t- $directory_path\n";
34+
printf "$result_find_inode\t\t- $directory_path\n" >> $path_file_log
35+
done
36+
}
37+
38+
_report_find_inode_system
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# find inode of the linux system
2+
Fix No Space Left on Device

bash-basic/linux-cve/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# script run fix cve

bash-basic/tcpdump/crontab

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SHELL=/bin/bash
2+
PATH=/sbin:/bin:/usr/sbin:/usr/bin
3+
MAILTO=root
4+
HOME=/
5+
6+
# For details see man 4 crontabs
7+
8+
# Example of job definition:
9+
# .---------------- minute (0 - 59)
10+
# | .------------- hour (0 - 23)
11+
# | | .---------- day of month (1 - 31)
12+
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
13+
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
14+
# | | | | |
15+
# * * * * * user-name command to be executed
16+
*/20 * * * * root check_tcpdump/kill_tcpdump.sh

bash-basic/tcpdump/kill_tcpdump.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
logPath="$DIR/log_kill_tcpdump"
5+
6+
log_message() {
7+
echo -e $1 >> $logPath
8+
}
9+
10+
kill_tcpdump() {
11+
12+
killall tcpdump
13+
}
14+
remove_log_tcpdump() {
15+
16+
for i in `seq 2 10`; do
17+
year=$(date -d "$i days ago" +"%Y")
18+
month=$(date -d "$i days ago" +"%-m")
19+
day=$(date -d "$i days ago" +"%-d")
20+
ymd=$year$month$day
21+
rm -rf "$DIR"/"$ymd"
22+
done
23+
}
24+
start_tcpdump() {
25+
"$DIR"/check_tcpdump.sh
26+
}
27+
28+
log_message "\n\n\n\n\n----------- Checking System Info -----------"
29+
log_message "Checking Time: $(date)"
30+
kill_tcpdump
31+
remove_log_tcpdump
32+
start_tcpdump

bash-basic/tcpdump/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# script auto tcpdump for everydays
2+
### you have add script run auto in the cronjob

bash-basic/tcpdump/run_tcpdump.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
year=$(date +"%Y")
6+
month=$(date +"%-m")
7+
day=$(date +"%-d")
8+
9+
hour=$(date +"%H")
10+
munites=$(date +"%M")
11+
second=$(date +"%S")
12+
13+
name=$(hostname)
14+
15+
hms=$hour$munites$second
16+
ymd=$year$month$day
17+
18+
mkdir -p "$CURRENT_DIR"/"$ymd"
19+
20+
DIRECTORY="$CURRENT_DIR"/"$ymd"
21+
22+
if [ -d "$DIRECTORY" ];
23+
then
24+
echo "Folder $DIRECTORY exists"
25+
sleep 2
26+
tcpdump -i eth1 -n -s 0 port 5060 -vvv -w "$CURRENT_DIR"/"$ymd"/log-eth1-"$name"-"$ymd"-"$hms".pcap &
27+
tcpdump -i eth0 -n -s 0 port 5060 -vvv -w "$CURRENT_DIR"/"$ymd"/log-eth0-"$name"-"$ymd"-"$hms".pcap &
28+
29+
elif [ ! -d "$DIRECTORY" ];
30+
then
31+
echo "Folder $DIRECTORY doesnt exists"
32+
mkdir -p "$CURRENT_DIR"/"$ymd"
33+
echo "Creating Foleder $DIRECTORY Done !!!"
34+
sleep 2
35+
tcpdump -i eth1 -n -s 0 port 5060 -vvv -w "$CURRENT_DIR"/"$ymd"/log-eth1-"$name"-"$ymd"-"$hms".pcap &
36+
tcpdump -i eth0 -n -s 0 port 5060 -vvv -w "$CURRENT_DIR"/"$ymd"/log-eth0-"$name"-"$ymd"-"$hms".pcap &
37+
fi

0 commit comments

Comments
 (0)