Help Me. The script should not exit until the user gives an input.
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.
Code:
#!/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"
Moderator's Comments:
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
Last edited by jim mcnamara; 08-10-2017 at 10:52 PM..
Hi,
I need to get the user input and execute a particular script based on the input provided.
For E.g. When I execute the script say Test.sh it should prompt "For which country I need to execute the script? (US/India)"
Based on the input as US or India from the user the execution of... (8 Replies)
Hello friends,
Kindly help me in developing a script that asks user to enter a value and will wait for 5 seconds for the feedback. If there is no answer from the user the script will perform exit or it will continue doing something else
Ex: If yu have a multi OS system i believe while... (3 Replies)
Hello
I am trying to create a user input shell scipt. The objective is user should enter the circuit number and the input is saved in a log file. If the user does not enter anything then the question should prompt it until the circuit no. is entered.
Can any one please correct the code below.... (3 Replies)
Hi Jim,
I have following script,i which i need to take dynamic value .
script,
nawk -v v1=grep"INT_EUR" $propertifilename | cut -d"=" -F2` -F'~' '{if (NF-1 !=v1)
{print "Error in " $0 " at line number "NR" tilde count " N-1}}' $filename
In the above script i want to use INT_EUR as a variable... (2 Replies)
i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled.
#!/bin/sh
echo " Enter your choice to continue y/Y OR n/N to quit "
read A
if
then
echo " user requested to continue "
##some commands... (7 Replies)
Hi, I want to write a script to check whether an user ID is used in my server and then create that user.
If the user ID is not used, I will echo something like "OK, continue" and then continue to execute the script. Else, I will echo something like "Used, exit" and then exit the script.
As... (4 Replies)
I'm writing a bunch of scripts to automatically configure Ubuntu and I want to run the code below to remove the white dots from the login screen:
sudo xhost +SI:localuser:lightdm
sudo su lightdm -s /bin/bash
gsettings set com.canonical.unity-greeter draw-grid false
The problem is that... (3 Replies)
Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Hello all..
so i have a problem i need to solve ..
#! /bin/bash
$SHELL
dtterm -title my_prog -e su -user -c 'export DISPLAY=:0.0 ; /path/to/my/prog' & 2> /dev/null
$SHELL
intr
exit
This script will work on solaris 10 system in right clikt menu - in a secure system so i need to... (0 Replies)