Member Avatar for Member #1163902

I need some help with the below please!

After installation of [Fedora] is completed, write a script called your LastName_StudentID.sh to obtain following options information:

  • Get information about your operating system,
  • Get information about hosts
  • Network interface and routing information
  • Display a list of users currently logged on display a list of recently logged in users,
  • The display used and free memory information,
  • Display if the Linux operating system is installed on physical or Virtual machine.

Dani AI

Generated

Below are compact, practical examples that expand on 's pointers and address @Ant's added Sections C and D. The snippets prefer modern tools when present, include simple fallbacks, and are written so the output can be redirected or copied into a final script named like LastName_StudentID.sh. Replace the placeholder LastName_StudentID with the actual last name and student ID.

#!/bin/bash
# LastName_StudentID.sh - quick system summary

# OS / kernel / host
if [ -r /etc/os-release ]; then . /etc/os-release; printf "%s %s\n" "$NAME" "$VERSION"; else uname -sr; fi
printf "Hostname: %s\n" "$(hostname -f 2>/dev/null || hostname)"

# Hosts file
[ -r /etc/hosts ] && echo "--- /etc/hosts ---" && sed -n '1,200p' /etc/hosts

# Network (prefer ip, fall back to ifconfig/route)
if command -v ip >/dev/null 2>&1; then ip -br addr; ip route show; else { command -v ifconfig >/dev/null 2>&1 && ifconfig -a; } ; route -n 2>/dev/null || true; fi

# Users and recent logins
echo "--- logged on ---"; who
echo "--- recent logins ---"; last -n 10

# Memory
echo "--- memory ---"; free -h 2>/dev/null || awk '/MemTotal|MemFree/ {print}' /proc/meminfo

# Virtual/physical check (best-effort)
if command -v systemd-detect-virt >/dev/null 2>&1; then systemd-detect-virt -v || true
elif [ -r /sys/class/dmi/id/product_name ]; then cat /sys/class/dmi/id/product_name
else echo "No quick virt-detect; use sudo dmidecode if available."
fi
#!/bin/bash
# Section C - create directory and optionally copy a file to TESTING

BASE="LastName_StudentID"
DEST="$HOME/$BASE/TESTING"
mkdir -p "$DEST"

read -p "Path of file to check: " SRC
[ -e "$SRC" ] || { echo "File not found: $SRC"; exit 1; }

# show permissions
printf "Permissions: "; [ -r "$SRC" ] && printf "r" || printf "-"; [ -w "$SRC" ] && printf "w" || printf "-"; [ -x "$SRC" ] && printf "x" || printf "-"; printf "\n"

if [ -w "$SRC" ]; then
  read -p "Copy to $DEST? (y/N): " ans
  case "$ans" in [Yy]*) cp -v "$SRC" "$DEST";; *) echo "Copy cancelled.";; esac
else
  echo "Copy denied: write permission missing on source."
fi
#!/bin/bash
# Section D - extract lines 20..30 and sort them
IN="LastName_StudentID_hotel.txt"
OUT="LastName_StudentID_Hotls.txt"
[ -r "$IN" ] || { echo "Missing input: $IN"; exit 1; }
sed -n '20,30p' "$IN" | sort > "$OUT"
printf "Wrote %s (lines 20..30, sorted)\n" "$OUT"

Notes and cautions: placeholders must be replaced with the real last name/student ID. Use quotes around path variables to handle spaces. dmidecode requires root; systemd-detect-virt is commonly available on Fedora and is a safe first check. Make scripts executable with chmod +x. These snippets are intentionally conservative (checks for available commands and fallbacks) so they run on a variety of Fedora installs.

Recommended Answers

All 3 Replies

Member Avatar for Member #1163902
Thank you so much, I tried to do it myself I got something very similar to yours. i'm stuck on the below:

Section C: File Management
Write a shell script to create a directory called “lastName_StudentID” and ask the user if he/she wants to copy a file to TESTING directory.

You should find out that the file has read, write and execute permission. If the file has write permission then copy the file to the directory; denied otherwise.

Section D: Pipe
Suppose we have a file called ‘lastName_StudentID_hotel.txt’ with 100 lines of hotel names, each name on a line. Write a script to print the hotel names from line number 20 to line number 30 inclusive. Store the results in a file called ‘lastName_StudentID_Hotls.txt’. Sort the file in alphabetical order.

@Ant, I looked at your top post and saw nothing about Section C and D. What you might be trying to do is to extend your discussion to include NEW QUESTIONS. Sorry but I won't do that. If you have new questions those are in new discussions. Otherwise you have discussions that never end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.