problem in a shell based project


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions problem in a shell based project
# 1  
Old 11-17-2010
problem in a shell based project

i have a bank project in shell script.it has a module called deposit.when i am entering an amount and commit a mistake like entering char instead of numbers and so on and repeating it, suppose 3 times,then it is rejected by amount validation code. every thing is fine upto these steps. but after 3 times if i give the correct amount then this new amount is added three times to the account rather than just once.
i dont know why
please help..


first getting old value of amount by grep command
and then adding new amount to it


i am replacing the old amount with new one using "sed" command
sed s/old/new details > file
mv file details

what to do?

wilshire soft
hyderabad
india
# 2  
Old 11-17-2010
break the loop when correct? Show us the loop, or are the three tries in a line? Use a loop.
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 11-17-2010
thanx for the quick reply
may be you are right ? i will check it
# 4  
Old 11-17-2010
Before making the old -> new, put a conditional check for the input with a counter.

1. use something like below for the validation
echo "asbc123" | tr -dc '[:alpha:]' #if something return its invalid

2. for each try increament the counter
check if the step1 not returning anything & step2<=3
proceed
else
do nothing
This User Gave Thanks to palsevlohit_123 For This Post:
# 5  
Old 11-17-2010
this is very funny situation
i tried the code on my laptop at home and its working fine
i dont know what goes wrong on the server with the code in office

tomorrow i will check it again in the office
for the while i have this code
################################
in deposit module
############
amtvalidation ()

{
len=`echo "$amt"|wc -c`
for((i=1;i<len;i++))
do
c=`echo "$amt"|cut -c$i`
case $c in
[0-9])continue;;
*)echo "invalid .enter:"
read amt
amtvalidation "$amt";;
esac
done
let r=amt%100
if [ $r -ne 0 ]
then
echo "enter amount in 100: "
read amt
amtvalidation "$amt"
fi
}

clear

echo "enter accno:"
read accno

echo "enter the amount:"
read amt
amtvalidation "$amt"

old=`grep -w "$accno" info|cut -d ":" -f7`

clear
sleep 1
echo "pre amt is $old "
let new=old+amt
sed "/$accno/s/$old/$new/" info > file
mv file info


echo
sleep 1
echo "added"
echo


n=`grep -w "$accno" info|cut -d ":" -f7`
sleep 1
echo "new amt is $n:"
echo


######################
in info file the red number is f7(field 7)
################
dha:jhjh:hgj@jhj.com:dha:8989898989:hjj:3800:123021
# 6  
Old 11-17-2010
Do you have a
Code:
#!/path/to/interpreter [one-option-like-f-in-sed-or-awk ]

line at the top of the script and made it executable to the executing id?

Are the interpreters the same version?
This User Gave Thanks to DGPickett For This Post:
# 7  
Old 11-17-2010
hiiiiii friend
i am very much new to shell script
i dont know that much of technicalities
please mention what should be added at top of script

---------- Post updated at 10:11 PM ---------- Previous update was at 10:09 PM ----------

the code i have pasted is working fine on my laptop but the same code gets wrong on my office server
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Open Source

Project planing - with Linux based solutions

Hello, Please suggest or share any of your experience for the following requests: Request: 1. Creation of the local network. The company will be in the field of IT. 10-15 persons. 10 will be physically in the office. The local network should be secured and all the files and... (0 Replies)
Discussion started by: AQwert
0 Replies

2. Solaris

Solaris based project?

Hi friends, I am a Computer Science student, and about to do my final year project. I am a big lover of Solaris and SPARC RISC computers, and I want to work on those computers in future. I want to become a System Administrator/Security Administrator etc on the Solaris stuff. Could you please tell... (1 Reply)
Discussion started by: gabam
1 Replies

3. Homework & Coursework Questions

Need ideas for graduation project based on unix or linux

Dear all, i am in last year of electronics department in engineering faculty i need suggestions for a graduation project based on unix or free bsd or linux and electronics "embedded linux " i think about embedded unix for example or device drivers please i need helps (1 Reply)
Discussion started by: MOHA-1
1 Replies

4. UNIX for Advanced & Expert Users

Need ideas for graduation project based on unix or linux

Dear all, i am in last year of electronics department in engineering faculty i need suggestions for a graduation project based on unix or free bsd or linux and electronics "embedded linux " i think about embedded unix for example or device drivers please i need helps (1 Reply)
Discussion started by: MOHA-1
1 Replies

5. UNIX and Linux Applications

Need ideas for graduation project based on unix or linux Need ideas for graduation project based on

Dear all, i am in last year of electronics department in engineering faculty i need suggestions for a graduation project based on unix or free bsd or linux and electronics "embedded linux " i think about embedded unix for example or device drivers please i need helps (1 Reply)
Discussion started by: MOHA-1
1 Replies

6. Hardware

Need ideas for graduation project based on unix or linux

Dear all, i am in last year of electronics department in engineering faculty i need suggestions for a graduation project based on unix or free bsd or linux and electronics "embedded linux " i think about embedded unix for example or device drivers please i need helps (1 Reply)
Discussion started by: MOHA-1
1 Replies

7. Solaris

building solaris-based enterprise router-firewall project

hi guys, its been a while since my last visit here, could not keep up the pace on this ever changing industry :) i'd just doing my home research under vmware to make a solaris-based router-firewall using zones - doing a lot of reading about zones & review solaris zone functionality. and... (4 Replies)
Discussion started by: stdout
4 Replies

8. Programming

Problem with kerberos cpp project

Hi All, I am having problem with kerberos kadmin library in c++. I am using red hat linux Enterprise Linux Server release 5 (Tikanga), and gcc c++ - 4.1.1-52.el4.i386. When I make a c project (main.c) and use function from kadmin library such as kadm5_init_krb5_context(&context); ... (2 Replies)
Discussion started by: amitp
2 Replies

9. Shell Programming and Scripting

project idia in shell

could any one provide me any new real time project idea in shell scripting i am learning shell script and wants to do some real time development . (1 Reply)
Discussion started by: useless79
1 Replies
Login or Register to Ask a Question