Validating $1 and $2 before using


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validating $1 and $2 before using
# 1  
Old 09-15-2003
Validating $1 and $2 before using

Hi there,

I'm trying to validate my $1 and $2 before I use them in the sqlplus update, I think I have the validation rules set correctly??? however when I test my script, it jumps straight into the sql. It doesn't seem to validate the vars....even when I know they are incorrect.

if [ $1 = '44*' ]; then
TEMP='echo $1 | cut -c2-'
MSISDN=0$TEMP
else
$1=MSISDN
fi

if [ $2 -ne '4[0-9]\{7,7\}$' ];then
echo "Please check $2 is a Cust_ref number'
else
$2=CUSTREF
fi

sqlplus -s ########/########## <<!
update tbl_entry set status='LOCKED' where msisdn='$MSISDN' and cust_ref='$CUSTREF' .......rest of sql;
commit;
exit;
!



Many thanks,
# 2  
Old 09-15-2003
Should these lines of code:

$1=MSISDN
$2=CUSTREF

really be:

MSISDN=$1
CUSTREF=$2

?
# 3  
Old 09-15-2003
Do you want $1 = '44*' or $1 -eq "44*"? Remember, single quotes mean the asterisk will be interpreted as an asterisk instead of a wildcard meaning any number of characters.

And I agree with mbb. At the very least, you can't assign values to $1, $2, etc...
# 4  
Old 09-16-2003
I may be wrong but I don't think

if [ $1 = 44* ]; then

Will work with wildcards

You may need to use the ksh version

[[ $1 = 44* ]] && ....

Matt.
# 5  
Old 09-17-2003
For troubleshooting purposes I would add several echo statements... in your script...so you can see the values of your variables as they are checked and assigned.

Im assuming $1 and $2 have values before this portion of your script?

Also, You assign CUSTREF to $2 but never assign a value to CUSTREF ???


ie:

echo $MSISDN and echo $CUSTREF both before during and after your IF/FI statements... so you can see what they are set to...

also put in a few "Sleep" statements so that it will run slower so you can read what is happening.


if [ $1 = '44*' ]; then
TEMP='echo $1 | cut -c2-'
MSISDN=$TEMP
echo $MSISDN
else
$1=MSISDN
echo $1
fi

sleep 10

if [ $2 -ne '4[0-9]\{7,7\}$' ];then
echo "Please check $2 is a Cust_ref number'
echo $CUSTREF
else
$2=CUSTREF
echo $2
fi

sleep 10
echo "Starting SQL portion"
sleep 10

sqlplus -s ########/########## <<!
update tbl_entry set status='LOCKED' where msisdn='$MSISDN' and cust_ref='$CUSTREF' .......rest of sql;
commit;
exit;
!
# 6  
Old 09-17-2003
Thanks for the replies.....My first problem, where I though the script was going starig into the slqplus was that the orignal script had been set in the PATH and that was executing before mine which is being updated.

I'm still having problems with the string validations though. When I try and run the script with two very wrong values I et syntax errors.....please help!!!!

./manually_lock_port_in_entry.sh 441111111111111111111111 412345678
./manually_lock_port_in_entry.sh[29]: 07[0-9]\{9,9\}: syntax error
./manually_lock_port_in_entry.sh[37]: 4[0-9]\{7,7\}: syntax error
441111111111111111111111 412345678




# Validate Script options, MSISDN and CUST_REF


if [ $1 = 44* ]
then
TEMP='echo $1 | cut -c2-'
MSISDN=0$TEMP
else
if [ $1 -ne "07[0-9]\{9,9\}" ]
then
echo "Please check MSISDN is valid"
else
MSISDN=$1
fi
fi

if [ $2 -ne "4[0-9]\{7,7\}" ];then
echo "Please check $2 is a Cust_ref number"
else
CUSTREF=$2
fi

echo $MSISDN $CUSTREF
# 7  
Old 09-17-2003
Hi nhatch,

The syntax errors are caused by the -ne being used with a value in quotes.

-ne shoudl be used with numbers.
If you are comping strings use !=

e.g.

if [ $1 != "07[0-9]\{9,9\}" ]

Hope this helps,

Matt.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validating the file

Hello All, I have the following file. The first column is Type. Always the file will have one H and one T type in between all D type reocrds. Need todo some validations. H|ABCD D|TAB N0003107809CD2013-11-14|RYAN|FRY|7 DR|RICHMOND HILL|GA|32431|X|C95|000009999|000000001|TAB||C0001 D|TAB... (3 Replies)
Discussion started by: karumudi7
3 Replies

2. Shell Programming and Scripting

awk for validating

HI, I am trying to write a validation script as below awk '($1=="ABC"&&$2="XYZ" ,then check the value in $8,$10 these columns should not be null. so their should be some corresponding value n the $8 and $10 column,if their is no value the script has to give error saying that at a... (2 Replies)
Discussion started by: gaur.deepti
2 Replies

3. UNIX for Dummies Questions & Answers

Validating a file

Pardon my ignorance but I am lost on how to do this I have a file called "Sample.txt", it is pipe delimited, it should have 13 fields. But some of the records do not, I would like to set up a shell script where I can pass in a parameter "Sample.txt" and it would split the file into records... (2 Replies)
Discussion started by: dgeehot
2 Replies

4. Shell Programming and Scripting

Validating commandline argument

Hi, I am calling a script script2.shl from script1.shl as below script2.shl "TABLE_NAME" -r 10 In that I have to validate the parameter 4. i.e : it should be only 10 20 30 40 50 I know that I can do it by checking like below if ]; then echo "TRUE" else echo "FALSE" fi ... (3 Replies)
Discussion started by: mr_manii
3 Replies

5. Shell Programming and Scripting

Validating IP address.

Hi All, This is a small snippet that I am using to validate the format of IP address.This is working fine. Since this is not elegant, please let me know if anyone has a better working code than the one below. Also I am planning to ping the ip address given by the user and check the $?... (3 Replies)
Discussion started by: nua7
3 Replies

6. Shell Programming and Scripting

validating data

I have a file like the following aaaaa00005bbbbb aaaaa00108bbbbb The code "00005" and "00108" need to be validated and the list of valid codes are stored in a database. While I loop through the file, should call a sql statement for every records to do the validation? or is... (1 Reply)
Discussion started by: joanneho
1 Replies

7. Shell Programming and Scripting

validating 10. IP address any way possible

HELP: validating IP addresses any way possible -------------------------------------------------------------------------------- I am trying to validate input from the user in a script. I thought is was easy to do using regular expressions but I can't figure out how to use REs in a... (1 Reply)
Discussion started by: nrodolfich
1 Replies

8. UNIX for Dummies Questions & Answers

validating userid

What's wrong with this syntax? It's part of my 'if' statement but it doesn't seem to pass and it keeps going to the 'else' part. I thought it says that userid must start with a non-numeric character and is between 6 and 10 characters long (alphanumeric). $userid|grep -Eq '^?\{6,10\}+$' if... (2 Replies)
Discussion started by: giannicello
2 Replies

9. Programming

validating input

how do i validate y script so that it only accepts values between 1 and 3 and against any character input, cause at the moment i can only validate against numbers outside 1 and 3 but not characters cheers (4 Replies)
Discussion started by: ruffenator
4 Replies

10. Shell Programming and Scripting

validating dates

This is what I have to check date entries in an interactive script with the end users... I use this to build control cards for a reporting utility supplied by a software vendor. I also want to check to make sure its a valid day based on the month (ie 30days has sept, april, june and Nov..)... ... (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question