Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script
# 1  
Old 07-08-2013
Shell script

I have one script.

Code:
#!/bin/ksh
[[ $# -lt 1 ]] && echo "Usage: $0 pattern (pattern can be gsx name or trunkgroup or point code)" && exit 1
egrep -h "$1" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent

Which works like this.

Code:
./abc.sh <input>

I have one requirement.

1. if input is Point code like 203-53-27

do this

else

that.


means. I want to control function of script based on input.
Code:
tcmg6so 209-68-71   MLWDWAAAGT0BIM1I MLWDWAAAGT0BIM1I 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED      528
tcmg6so 209-68-71   PTLDOR62GT2BIM1I PTLDOR62GT2BIM1I 209-68-66            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED     1080
tcmg6so 209-68-71   PTLDOR62GT2BSS1I PTLDOR62GT2BSS1I 209-68-66            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED       48

How to identify if input is any Point code or else any word like tcm or CIRCU.
Code:
bash-3.00$ abc TACNWADNCM6BWW1O
tcmg1so 209-68-71   TACNWADNCM6BWW1O TACNWADNCM6BWW1O 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED      792
tcmg3so 209-68-71   TACNWADNCM6BWW1O TACNWADNCM6BWW1O 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED     1152
tcmg6so 209-68-71   TACNWADNCM6BWW1O TACNWADNCM6BWW1O 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED     1056
bash-3.00$
bash-3.00$ abc 209-65-23
dnvg1so 209-68-36   TACNWADNCM6AE92I TACNWADNCM6AE92I 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED       24
tacg1so 227-125-20  TACNWADNCM6ASS1I TACNWADNCM68SS1B 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED       48
tacg1so 227-125-20  TACNWADNCM6AWW1O TACNWADNCM6AWW1O 209-65-23            CIRCUITLO2HI   ALLCICS    INSERVICE    ENABLED      528
tacg2so 227-125-20  TACNWADNCM6AIM1I TACNWADNCM68IM1B 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED     1512
tacg2so 227-125-20  TACNWADNCM6ASS1I TACNWADNCM68SS1B 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED       24
tacg3so 227-125-20  TACNWADNCM6AIM1I TACNWADNCM68IM1B 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED     1536
tacg4so 227-125-20  TACNWADNCM6AIM1I TACNWADNCM68IM1B 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED     2232
tacg5so 227-125-20  MLWDWAAAGT0AIM1I MLWDWAAAGT08IM1I 209-65-23            CIRCUITHI2LO   ALLCICS    INSERVICE    ENABLED      552
tacg5so 227-125-20  TACNWADNCM6AE91I TACNWADNCM6AE91I 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED       24
tacg5so 227-125-20  TACNWADNCM6AWW1O TACNWADNCM68WW1O 209-65-23            CIRCUITLO2HI   ALLCICS    INSERVICE    ENABLED     1248
tacg6so 227-125-20  MLWDWAAAGT0AIM1I MLWDWAAAGT08IM1I 209-65-23            CIRCUITHI2LO   ALLCICS    INSERVICE    ENABLED      840
tacg6so 227-125-20  TACNWADNCM6AWW1O TACNWADNCM68WW1O 209-65-23            CIRCUITLO2HI   ALLCICS    INSERVICE    ENABLED     1224
tcmg1so 209-68-71   TACNWADNCM6BSS1I TACNWADNCM6BSS1I 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED       72
tcmg1so 209-68-71   TACNWADNCM6BWW1O TACNWADNCM6BWW1O 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED      792
tcmg2so 209-68-71   TACNWADNCM6BIM1I TACNWADNCM6BIM1I 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED     1872
tcmg3so 209-68-71   TACNWADNCM6BIM1I TACNWADNCM6BIM1I 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED     1320
tcmg3so 209-68-71   TACNWADNCM6BWW1O TACNWADNCM6BWW1O 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED     1152
tcmg4so 209-68-71   TACNWADNCM6BIM1I TACNWADNCM6BIM1I 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED     2088
tcmg5so 209-68-71   MLWDWAAAGT0BIM1I MLWDWAAAGT0BIM1I 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED      864
tcmg6so 209-68-71   MLWDWAAAGT0BIM1I MLWDWAAAGT0BIM1I 209-65-23            CIRCUITLO2HI   NOCICS     INSERVICE    ENABLED      528
tcmg6so 209-68-71   TACNWADNCM6BWW1O TACNWADNCM6BWW1O 209-65-23            CIRCUITHI2LO   NOCICS     INSERVICE    ENABLED     1056
bash-3.00$

I want script to identify input whether it's its point code or not. if it's point code do something, else in any other case of input do that.

---------- Post updated at 06:38 PM ---------- Previous update was at 06:35 PM ----------

in case of point code i want exact match.

Like

Code:
egrep -h "$1" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent|grep -w "$1"

using -w it matched exact.

in case of other input (not point code ) I want this to function like normal grep.

Like

Code:
egrep -h "$1" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent


Last edited by Scott; 07-08-2013 at 10:09 AM.. Reason: Code tags, PLEASE!
# 2  
Old 07-08-2013
What do you exactly mean by "Point code"? Is it always XXX-XX-XX where all the X's are integers? (3 X's-2 X's-2 X's)
# 3  
Old 07-08-2013
Hi gacanepa,

Input to the script can be PointCode or word.

Code:
./abc 209-57-73

./abc tcm

./abc SHOKCA0

I want script to identify $1 that command line input and do operation based on that.

If script identifies $1 is Point-code then it will do certain function, else it will do other function.

I just want one one if - else script.

I don't know how script will identify if it's PointCode or some thing else.

---------- Post updated at 07:28 PM ---------- Previous update was at 07:25 PM ----------

one logic to the find the input will be like this, if Input starts with an integer or not.

If starts with integer
do this,

else
do this.

Last edited by Scott; 07-08-2013 at 11:33 AM.. Reason: Code tags
# 4  
Old 07-08-2013
This does the job:
Code:
#!/bin/bash
glob="[[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]"
if [[ ${1} == $glob ]]; then
    echo "yes"
else
    echo "no"
fi

This is called "Character classes" and you can find a good tutorial here.
Let me know if you have further questions.
# 5  
Old 07-08-2013
Hi Gacanepa.

Thanks for reply, little improvement required numbers can be 1 to 3 it's not 3x-2y-2z

I tried something, but not able to match correctly.
Code:
bash-3.2$ cat raza
#!/usr/bin/bash
Input="$1"
echo "$Input"
if [[ "$Input"="[0-9]+-[0-9]+-[0-9]+" ]];
then
echo "HELLO"
PC=`echo "$Input" |sed -e 's/^[0]*//g'|sed -e's/-[0]*/-/g'`
grep -hw "$PC" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
else
echo "Hi"
grep -h "$Input" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
fi

bash-3.2$

Point code can be 209-78-125 , 27-67-85, 209-127-56 like this.
So please improve it.
Moderator's Comments:
Mod Comment What about using code tags then...
# 6  
Old 07-08-2013
Please use code tags. It makes your code more understandable - I'll be more than glad to help Smilie.
# 7  
Old 07-08-2013
Code:
 bash-3.2$ cat raza
#!/usr/bin/bash
Input="$1"
echo "$Input"
if [[ "$Input"="[0-9]+-[0-9]+-[0-9]+" ]];
then
echo "HELLO"
PC=`echo "$Input" |sed -e 's/^[0]*//g'|sed -e's/-[0]*/-/g'`
grep -hw "$PC" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
else
echo "Hi"
grep -h "$Input" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
fi
bash-3.2$

don't know how to use code tag. Just tried this, hope it is fine.

---------- Post updated at 09:23 PM ---------- Previous update was at 09:22 PM ----------

Code:
bash-3.2$ cat raza
#!/usr/bin/bash
Input="$1"
echo "$Input"
if [[ "$Input"="[0-9]+-[0-9]+-[0-9]+" ]];
then
echo "HELLO"
PC=`echo "$Input" |sed -e 's/^[0]*//g'|sed -e's/-[0]*/-/g'`
grep -hw "$PC" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
else
echo "Hi"
grep -h "$Input" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
fi
bash-3.2$

---------- Post updated at 09:24 PM ---------- Previous update was at 09:23 PM ----------

My test criteria in If statement is not working well.

Last edited by vbe; 07-08-2013 at 01:00 PM.. Reason: replaced icode by code...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script newbie- how to generate service log from shell script

Hi, I am totally a newbie to any programming languages and I just started an entry level job in an IT company. One of my recent tasks is to create a script that is able to show the log file of linux service (i.e. ntpd service) lets say, if I run my script ./test.sh, the output should be... (3 Replies)
Discussion started by: xiaogeji
3 Replies

2. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

3. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

5. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

6. Shell Programming and Scripting

Correct shell script to Call One shell script from another shell script

Hi All, I have new for shell scripting. Problem : I have one scrip at serv1 and path of server is /apps/dev/provimage/scripts and script name:extract_ancillary.bat. I need to call this script at server2(my working server) and execute at server2 . Please let me know how to build the... (5 Replies)
Discussion started by: Vineeta Nigam
5 Replies

7. Shell Programming and Scripting

call another shell script and pass parameters to that shell script

Hi, I basically have 2 shell scripts. One is a shell script will get the variable value from the user. The variable is nothing but the IP of the remote system. Another shell script is a script that does the job of connecting to the remote system using ssh. This uses a expect utility in turn. ... (2 Replies)
Discussion started by: sunrexstar
2 Replies

8. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

9. Shell Programming and Scripting

invoking a shell script inside cgi shell script

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

10. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies
Login or Register to Ask a Question