Sponsored Content
Top Forums Shell Programming and Scripting How to handle scripts that expect an input Post 302413027 by ladyAnne on Wednesday 14th of April 2010 09:47:40 AM
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
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 11:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy