View Single Post
  #10 (permalink)  
Old 03-09-2010, 07:21 AM
techhelp techhelp is offline
Member
 
Posts: 12
Default

Quote:
Originally Posted by uxbod View Post
Just add in before the following code
Code:
# Make sure we have the domain name
if [ -z "${DOMAIN}" ]
then
    echo "${USAGE}"
    exit ${E_WRONGARGS}
fi
the following line as by default zimbra cannot write to /opt/zimbra
Code:
cd /tmp
I am running as su - zimbra
copied the script to /tmp
added all lines as best I understood and end up with

zimbra@webmail:/tmp$ automailcollect.sh -d mydomain.here -i 3m
Processing intervals for domain mydomain.here - setting interval to 3m...
ERROR: service.INVALID_REQUEST (invalid request: can only be used with "zmprov -l/--ldap")
Nothing to do!
/bin/automailcollect.sh: line 99: commands.zmprov: No such file or directory
zimbra@webmail:/tmp$

Below is the code I am currently working with, maybe I have some other issue? Possibly I added/deleted lines from the original script. Would you mind taking a look and let me know what you think, and if I can impose to have you correct any glaring mistakes added by myself. I feel so vulnerable trying to make this work. I am too M$ oriented and maybe I bit off too much with Zimbra... but I sure love my *nix box now

Code:
#!/bin/bash

# This is a script to go through all users of a domain
# and set the zimbraDataSourcePollingInterval attribute
# for all external accounts to the specified value.

# $1 = domain name
# $2 = polling interval in seconds

# Default Settings
DEFAULT_INTERVAL=60 # Default polling interval is 60 seconds

# Return codes

_OK=0
E_WRONGARGS=85 # Wrong arguments


USAGE="Usage: `basename ${0}` -d domain-name [-i interval]"
INTERVAL=${DEFAULT_INTERVAL}

# ------- Begin Script -------

# Parse command-line arguments
while [ $# -gt 0 ]; do
case "${1}" in
-d|--domain)
DOMAIN=${2}
shift
;;

-i|--interval)
INTERVAL=${2}
shift
;;

*)
echo "${USAGE}"
exit ${E_WRONGARGS}
esac

shift # Check next set of parameters
done

# Make sure we have the domain name
if [ -z "${DOMAIN}" ]
then
echo "${USAGE}"
exit ${E_WRONGARGS}
fi

# Make sure there are no .ds files
rm -f *.ds

# Make sure the commands.zmprov file is gone
if [ -e commands.zmprov ]
then
rm -f commands.zmprov
fi

echo "Processing intervals for domain ${DOMAIN} - setting interval to ${INTERVAL}..."

# Loop through all accounts in domain
for ACCOUNT in `zmprov gaa ${DOMAIN}`
do
echo "Searching account ${ACCOUNT}..."

# Create a list of data source names for this account
zmprov gds ${ACCOUNT} | grep zimbraDataSourceId | awk -F': ' '{print $2}' > ${ACCOUNT}.ds

# Loop through all data source names and set the interval
for DSID in `cat ${ACCOUNT}.ds`
do
echo "Found data source ${DSID}..."

# Set the interval
echo "mds ${ACCOUNT} ${DSID} zimbraDataSourcePollingInterval ${INTERVAL}" >> commands.zmprov
done

# When we're finished with the data source file, remove it
rm -f ${ACCOUNT}.ds
done

# Run the commands
if [ -e commands.zmprov ]
then
echo "Running zmprov..."
cat commands.zmprov
else
echo "Nothing to do!"
fi

# Make sure we have the domain name
if [ -z "${DOMAIN}" ]
then
echo "${USAGE}"
exit ${E_WRONGARGS}
fi

zmprov -l < commands.zmprov

cd /tmp

# Delete the file
rm -f commands.zmprov

# All is well, exit here
exit ${S_OK}
# ------- End Script -------
Reply With Quote