We use cookies to ensure you get the best experience on our website.
#!/bin/bash
# Check if the user is root
if [ "$EUID" -ne 0 ]; then
echo "Script must be run as root. Run it with sudo."
exit 1
fi
# Check if the target directory already exists
mount_point="/mnt/share"
if [ ! -d "$mount_point" ]; then
echo "Creating target directory: $mount_point"
mkdir -p "$mount_point"
fi
# Function to mount the network share
mount_share() {
echo "Mounting //share/ to $mount_point"
mount -t cifs -o username=yourUsername,password=yourPassword //share/ "$mount_point"
# Check if the mounting was successful
if [ $? -eq 0 ]; then
echo "Mounting successful."
else
echo "Error during mounting. Check if you provided correct login credentials."
exit 1
fi
}
# Function to unmount the network share
umount_share() {
echo "Unmounting network share from $mount_point"
umount "$mount_point"
# Check if unmounting was successful
if [ $? -eq 0 ]; then
echo "Unmounting successful."
else
echo "Error during unmounting."
exit 1
fi
}
# Check if the script was run with the "umount" argument
if [ "$1" == "umount" ]; then
umount_share
else
mount_share
fi
Cześć Podróżniku!
Ta strona ma nie być typowym poradnikiem w IT, Głównym jej cel to zapisanie krótkich notatek, które mogą się przydać w codziennym życiu podczas korzystania/konfiguracji różnych urządzeń np. Ustawienia DHCP na Routerze Cisco, Ustawieniu Karty sieciowej na Linuxie itp.
Wszelkie prawa zastrzeżone
Dodaj komentarz