Last active
June 19, 2023 16:40
-
-
Save samsesh/f2100bd384601a4c333da919be6918f2 to your computer and use it in GitHub Desktop.
mount s3 storage to linux server scprit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Prompt for necessary information | |
read -p "Enter S3 bucket name: " bucket_name | |
read -p "Enter the mount point directory path: " mount_point | |
# Provide example and get mount type | |
echo "" | |
echo "1. To add the mount to /etc/fstab" | |
echo "" | |
echo "2. To add the mount to crontab" | |
echo "" | |
read -p "Enter your choice (1 or 2): " choice | |
if [[ $choice == "1" ]]; then | |
# Add to /etc/fstab | |
read -p "Enter the username for fstab entry: " username | |
echo "s3fs#${bucket_name} ${mount_point} fuse _netdev,allow_other 0 0" | sudo tee -a /etc/fstab | |
echo "Added the following entry to /etc/fstab:" | |
echo "s3fs#${bucket_name} ${mount_point} fuse _netdev,allow_other 0 0" | |
echo "Please ensure that you have created the appropriate ~/.passwd-s3fs file with your AWS credentials." | |
elif [[ $choice == "2" ]]; then | |
# Add to crontab | |
crontab_entry="@reboot s3fs ${bucket_name} ${mount_point} -o passwd_file=~/.passwd-s3fs" | |
(crontab -l 2>/dev/null; echo "$crontab_entry") | crontab - | |
echo "Added the following entry to crontab:" | |
echo "$crontab_entry" | |
echo "Please ensure that you have created the appropriate ~/.passwd-s3fs file with your AWS credentials." | |
else | |
echo "Invalid choice. Please enter either '1' or '2'." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Enter S3 bucket name: my-s3-bucket
Enter the mount point directory path: /mnt/s3-mount
Example:
To add the mount to /etc/fstab
To add the mount to crontab
Enter your choice (1 or 2): 1
Enter the username for fstab entry: myuser
Added the following entry to /etc/fstab:
s3fs#my-s3-bucket /mnt/s3-mount fuse _netdev,allow_other 0 0
Please ensure that you have created the appropriate ~/.passwd-s3fs file with your AWS credentials.