I am new to bash. I will kindly ask for help from someone who can help me with this problem. I have created a script that makes a backup. Next step would be to make this script run at some certain timestamp in the future. I know I can do this with crontab. My problem is that the script requires some output from the user in order to run properly. (As you can see it asks for the Path) What I need to do is to make the script to take an argument (the path) so It can be runned like this: backup.sh -path=/tmp/myfoldertobackup From what I just read, it seems I have to use getopts but still this is very confusing to me. It looks like I also need to set the case when no argument is entered. Please help!
Any advice would be greatly appreciated! Thank you!!!
#!/bin/bash
#Simple backup script for onee.newdomain.tk
echo - e "Please tell me the path of directory you'd like to backup?"
read directory
cd $directory
mkdir backup
#mkdir "backup_$(date +'%Y_%m_%d__%H_%M_%S')"
SOURCEDIR=$directory
tar -czvf public.tgz public_html
mysqldump -u onee -pjFztm3s72anA oneex > onee.mysqlbackup.sql
mv public.tgz $directory/backup/
mv onee.mysqlbackup.sql $directory/backup/
mv backup backup.`date +"%d-%m-%Y"`
echo "==============================="
echo "Done!"
echo "==============================="