Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
M
mohammad_ali111
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammad.ali
mohammad_ali111
Commits
4361a560
Commit
4361a560
authored
Jun 30, 2024
by
mohammad.ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
parent
66531148
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
0 deletions
+134
-0
README.md
README.md
+134
-0
No files found.
README.md
View file @
4361a560
HOMEWORK LINUX
EX1:
script :
#!/bin/bash
if
[
"$#" -ne 3
]
; then
echo "Usage: $0 oldword newword extension"
exit 1
fi
oldword=$1
newword=$2
extension=$3
find . -type f -name "
*
.$extension" -exec sed -i "s/$oldword/$newword/g" {} +
echo "All occurrences of '$oldword' have been replaced with '$newword' in all .$extension files."
in terminal :
chmod +x name_of_script
./name_of_script oldword newword txt
EX2 :
in teminal :
a-
mkdir ~/new_folder
cd ~/new_folder
b-
for i in {1..10}; do for j in {a..z}; do touch "file${i}_${j}"; done; done
c-
for i in {1..10}; do echo "Hello Linux" > "file${i}_x"; done
d-
for letter in {a..z}; do
mkdir -p "$letter"
mv
*
_"$letter" "$letter"/
done
e-
find . -type f
\(
-name '
*3*
' -o -name '
*4*
'
\)
-delete
EX3 :
in script :
#!/bin/bash
# alive2.sh
# Checks to see if a range of hosts are alive
# Usage: alive2.sh 192.168.1.7-192.168.1.123
# Function to display usage
usage() {
echo "Usage: $0 start_ip-end_ip"
exit 1
}
# Check if the correct number of arguments are provided
if
[
"$#" -ne 1
]
; then
usage
fi
# Validate IP range format
if
[
[ ! "$1" =~ ^([0-9
]
{1,3}
\.
){3}
[
0-9
]
{1,3}-(
[
0-9
]
{1,3}
\.
){3}
[
0-9
]
{1,3}$ ]]; then
echo "Invalid IP range format."
usage
fi
start_ip=${1%-
*
}
end_ip=${1#
*
-}
# Convert IP to integer
ip_to_int() {
local a b c d
IFS=. read -r a b c d <<< "$1"
echo $((a
* 256 ** 3 + b *
256
**
2 + c
*
256 + d))
}
int_to_ip() {
local ip dec=$1
for e in {3..0}; do
((octet = dec / (256
**
e)))
((dec -= octet
* 256 *
*
e))
ip+=$octet.
done
echo "${ip%.}"
}
if
[
"$(ip_to_int "$start_ip")" -gt "$(ip_to_int "$end_ip")"
]
; then
echo "Start IP must be less than or equal to end IP."
exit 1
fi
# Iterate through IP addresses
current_ip=$(ip_to_int "$start_ip")
end_ip_int=$(ip_to_int "$end_ip")
while
[
"$current_ip" -le "$end_ip_int"
]
; do
host=$(int_to_ip "$current_ip")
ping -c2 "$host" &> /dev/null
if
[
$? -eq 0
]
; then
echo "$host is UP"
else
echo "$host is DOWN"
fi
((current_ip++))
done
in terminal :
cd /path/to/your/directory
git init
git add name_of_script
git commit -m "Initial commit of name_of_script"
git remote add origin https://github.com/mohammad/network-check.git
git push -u origin master
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment