How to handle scripts that expect an input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to handle scripts that expect an input
# 1  
Old 04-14-2010
How to handle scripts that expect an input

Hi

I would like to know how to handle my script that expects an input when calling the script and the user doesn't enter anything, I need to re-direct to my helpfile.

Bascically here is my script:

Code:
 
#!/bin/bash
 
csvdir="/var/local/dsx/csv/general"
csvfile="$csvdir/$csvfile"
dsxdir="/var/local/dsx/import"
dsxfile="$dsxdir/$dsxfile"
 
function displayHelp()
{
echo ""
echo " Usage: ./Import_PlannedCELL.sh [ -c -d ]"
echo ""
echo " -c, --csvfile identified by the input file in csv format "
echo " -d, --dsxfile identified by the output file in dsx format "
echo " -h, --help identified by the help menu "
echo ""

}
 
while getopts " c: d: h " option
do
case $option in
c ) csvfile="$OPTARG";;
d ) dsxfile="$OPTARG";;
h | ? | * ) displayHelp;exit;;

esac;
done
cat $csvdir/$csvfile | csvdsx -ePlanned \
-iCell:CELLID \
-cCells%BTS:SITEID^Cell:CELLID \
-sCell:CELLID \
-xCELLID,SITEID \
->$dsxdir/$dsxfile

if the user enters :

Code:
./script


instead of :

Code:
./script -h

how can i call my help function

I though this will help:

Code:
h | ? | * ) displayHelp;exit;;

but it only calls the help if I enter anything other than the specified getops options.

I need it to work also for whitespaces.

This is what I get when I try without a character:

Code:
$ ./import.sh
Warning: program compiled against libxml 207 using older 206
I/O warning : failed to load external entity "/var/local/dsx/import//var/local/dsx/import/"
failed to parse new file /var/local/dsx/import//var/local/dsx/import/

It is reading the file anyway

Thank you kindly for your help
# 2  
Old 04-14-2010
hi,
try using * as a separate part instead of combining it. Hope this helps.

snippet from ABS guide,

case $( arch ) in # "arch" returns machine architecture.
# Equivalent to 'uname -m' ...
i386 ) echo "80386-based machine";;
i486 ) echo "80486-based machine";;
i586 ) echo "Pentium-based machine";;
i686 ) echo "Pentium2+-based machine";;
* ) echo "Other type of machine";;
esac



Regards,
busyboy
# 3  
Old 04-14-2010
Hi

I have tried this as well and it doesn't seem to work.

Can you please suggest other alternatives.

Thank you for your help.

Regards

LadyAnne
# 4  
Old 04-14-2010
check the number of arguments
Code:
if [[ $# -eq 0 ]]; then
  display_help
  exit 1
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripts triggered via 'expect' - stderr lost

I have a bash script on server that runs fine when run interactively and writes stderr output to a file. However, when invoked through a 'expect' script run on Mac OS my laptop which does ssh to the server : generates the expected file, but file has no content. I suspect the stderr is getting... (1 Reply)
Discussion started by: sdudc
1 Replies

2. Shell Programming and Scripting

Input in expect script

Hi, i have one problem with this script: ------------------------------- cat hostid_gathering #!/bin/bash cat /home/user1/ip_switch | while read LINE; do echo $LINE /home/user1/expect_script2 done ------------------------------ cat /home/user1/expect_script2 #!/usr/bin/expect... (6 Replies)
Discussion started by: elilmal
6 Replies

3. Shell Programming and Scripting

Handle occasional condition in expect script

Hi, I am using Solaris OS, I want to handle an occasional expression in expect script while logging into a remote server with ssh. In normal scenario the expected expression is as below, spawn ssh $user@$ip expect "assword:" send "$password\r" but in a condition when the remote server... (2 Replies)
Discussion started by: varunksharma87
2 Replies

4. UNIX for Dummies Questions & Answers

Difference between using Here document and Expect in scripts

Hi, I am confused between using here document and using expect for writing interactive shell scripts(like changing password ,FTP or doing su). My questions are : 1)Why here documents cant change password from shell script. 2)Why we need to use expect for same? 3) Can Sourcing a script can do... (2 Replies)
Discussion started by: kailash19
2 Replies

5. Shell Programming and Scripting

Need help using expect in shell scripts

hi all, i have this script that accepts passwords automatically and its working in one host only. my problem is how will i use it if i need it to run in more than one host/server let say by using "for loop statement" working : spawn bundle linux -r hostname checkpath... (2 Replies)
Discussion started by: linuxgeek
2 Replies

6. Shell Programming and Scripting

help to handle the expect script issue

Hi experts I know the expect script can match the terminal output to run the the following cmd I write a script with expect named "test", I want to run ten "test" with background running, for ((i=1;i<=10;i++) do ./test -n $i done I find all the output of test will print on one... (0 Replies)
Discussion started by: yanglei_fage
0 Replies

7. Shell Programming and Scripting

how do I handle ssh response with expect

I am trying to write an expect script that trys to telnet, if telnet fails, trys to ssh to a remote network devices. The script works fine until the following is received : spawn telnet 10.3.2.24 Trying 10.3.2.24... telnet: connect to address 10.3.2.24: Connection refused 10.3.2.24 is... (2 Replies)
Discussion started by: popeye
2 Replies

8. Shell Programming and Scripting

Calling expect scripts from other expect scripts

Hi, First, let me explain the issue I am trying to solve. We have a lot of expect scripts with the duplicated send/expect commands. So, I'd like to be able to extract the duplicated code into the common scripts that can be used by other scripts. Below is my test where I am trying to call... (0 Replies)
Discussion started by: seva
0 Replies

9. Shell Programming and Scripting

flexible sed command needed to handle multiple input types

Hello, I need a smart sed command that can take any of the following two as an input and give below mentioned output. As you can see, I am trying to convert some C code INPUT: struct abc_sample1 { char myString; UINT16 myValue1; ... (2 Replies)
Discussion started by: SiftinDotCom
2 Replies
Login or Register to Ask a Question