ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
im new to linux
we have 2 scripts i can run, bith work seperately, but i want to combine it
can anyone help me? this is for our VOIP PBX, what it does, it shows me the passwords for the extension accounts, and one shows me the DID;s aka the alias
this one shows password:
#!/bin/bash
# Show the passwords of all users:
function get_xml()
{
gawk -v tag=$1 'BEGIN{regex="<" tag ">([^<]*)</" tag ">";}{ match($0, regex, m); for(i = 1;; i++) { if(!(i in m)) break; printf("%s\n",m[i]);}}' $2
}
for user in users/*.xml
do
name=${user:6} # only the name
idx=${name%.xml} # only the number
type=$(get_xml type $user)
if [ "$type" == extensions ]; then
id=$(get_xml id $user)
primary=$(get_xml alias $user)
domain=$(get_xml domain user_alias/$primary.xml)
for d in domain_alias/*.xml
do
dom=$(get_xml domain $d)
if [ -z "$dom" -a "$dom" == "$domain" ]; then
domain_name=$(get_xml name $d)
break
fi
done
dialplan=$(get_xml dial_plan $user)
if [ -z "$dialplan" ]; then
plan="Default"
else
plan=$(get_xml name dial_plan/$dialplan.xml)
fi
password=$(get_xml password extensions/$id.xml)
pin=$(get_xml mb_pin extensions/$id.xml)
username=$(get_xml name user_alias/$primary.xml)
if [ -z "$pin" ]; then
echo $domain $username $password \($plan\)
else
echo $domain $username $password \($plan\) [$pin]
fi
fi
done
this one shows DID, i want to take them and make it into 1.
#!/bin/bash
# Show all account names that are a telephone number:
function get_xml()
{
gawk -v tag=$1 'BEGIN{regex="<" tag ">([^<]*)</" tag ">";}{ match($0, regex, m); for(i = 1;; i++) { if(!(i in m))\
break; printf("%s\n",m[i]);}}' $2
}
for alias in user_alias/*.xml
do
name=${alias:11} # only the name
idx=${name%.xml} # only the number
name=$(get_xml name $alias)
if [ -z "$name" -o "${#name}" -lt 8 ]; then continue; fi
user=$(get_xml user $alias)
domain=$(get_xml domain $alias)
domainname=$(get_xml name domains/$domain.xml)
echo $name $domainname
done
In general terms, you have to make sure the variable names don't conflict between the two scripts, then just remove the #!/bin/bash from the second one and add it to the first. If there were any exit codes in the first script that would terminate it early you'd have to remove those too, but I don't see any here.
And since the second script resets the variables anyway, there may be no need to do anything special. Go ahead and try combining them and see what happens.
When it all comes down to it, you just have to make sure the individual commands still run and that nothing stops the script before you want it to. A shell script generally just executes commands in the order it comes across them.
By the way, please use [code][/code] tags around your script code, to help preserve formatting and to keep everything readable.
Distribution: RHEL4, RHEL5, CentOS, Customized Linux
Posts: 11
Rep:
you could also make a separate file ex. runAll.sh and run both of your scripts with that file if you want to keep the two original scripts as separate entities. Your runAll.sh file would look something like...
i want to combine both of them into the same script,
my problem is i dont understand how to read the script
all the functions of that scrpt i want to combine
Distribution: RHEL4, RHEL5, CentOS, Customized Linux
Posts: 11
Rep:
If you want to combine them into one function, it looks like you just need to copy the following function into the first script file since you are already using the first function, get_xml(), in both...
Code:
for alias in user_alias/*.xml
do
name=${alias:11} # only the name
idx=${name%.xml} # only the number
name=$(get_xml name $alias)
if [ -z "$name" -o "${#name}" -lt 8 ]; then continue; fi
user=$(get_xml user $alias)
domain=$(get_xml domain $alias)
domainname=$(get_xml name domains/$domain.xml)
echo $name $domainname
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.