Jump to content

linux script


hosted

Recommended Posts

  • 1 month later...

is it possible to be able to also add that it should include the Domain name in the results when using the following script

 

#!/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)
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 $username $password \($plan\)
else
  echo $username $password \($plan\) [$pin]
fi
 fi
done

Link to comment
Share on other sites

is it possible to be able to also add that it should include the Domain name in the results when using the following script

 

This should do the domain name

 

#!/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 $username $password \($plan\)
else
  echo $username $password \($plan\) [$pin]
fi
 fi
done

Link to comment
Share on other sites

doesnt show the domain name

also it works much slower then the original code, this one takes time in between the results

 

If you echo the 'domain_name', it will show the domain name.

It will be slower (depending on the number of accounts and/or number of domain) because, it has to run another loop for every account.

Link to comment
Share on other sites

ok, i added the following codes, but it only shows the domain alias, not the full name

also its extremely slow, the one i posted on top was much quicker

 

#!/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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...