Hi everyone, I'm new here and just a beginner in linux scripting.
Just want to ask for help on this one.
I am trying to create a script that will accept user input (year-month and user/s).
I wanted to have the script to continue running, until the user inputs a DATE and name/s of user/s.
Using the script below, when you do not input anything, it will echo "Please enter your start date" and will end the script, forcing you to run the script again. Same with the end date and user/s.
Hope someone would help me.
Thank you very much.
#!/bin/bash
#This script is used to extract GWI Restored Materials within a month from specified users.
#Date range used should be in this format: YYYY-MM.
#Users input should be in this format: "'nabaguisa','ccbacong','pmvito'". Double quotes are important to accept the names.
DATE1=$1
DATE2=$2
USERS=$3
DIR=/root/Desktop/GWI_Restored_Materials
echo "Please input start date: [ YYYY-MM ], followed by [ENTER] "
read DATE1
if [ -z "$DATE1" ]; then
echo "Please enter your start date"
else
echo " "
echo "Please input end date: [ YYYY-MM ], followed by [ENTER] "
read DATE2
if [ -z "$DATE2" ]; then
echo "Please enter your end date"
else
echo " "
echo "Please input user/s: [ 'user1' ], followed by [ENTER] "
echo "Multiple users should be separated by a comma [,]. Ex: 'user1','user2','user3'...."
read USERS
if [ -z "$USERS" ]; then
echo "Please enter user/s"
else
echo " "
echo "Extracting Materials from $DATE1 to $DATE2 by user/s $USERS"
Artificially truncated this long command line:
adt "select xfh_dest_min_id, xfh_source_filename, XFH_CREATE_BY, xfh_source_svc_handle as Source, xfh_dest_svc_handle as Destination, xfh_data_done/1024/1024 as
filesize_MB, xfh_create_ts from ardome_xfer_history where xfh_source_svc_handle='tsm0' and XFH_CREATE_BY in ($USERS) and xfh_create_ts>'$DATE1-01 00:00:00'
and xfh_create_ts<'$DATE2-01 00:00:00'" > $DIR/"$DATE1"_"$DATE2".txt
echo " "
echo "File has been exported to $DIR"
echo " "
echo "User armedia is copying file to NAS/Documentations/MonthlyReport_NEWSLA (password might be needed)"
scp $DIR/"$DATE1"_"$DATE2".txt
fi
fi
fi
exec bash