3 # Rename an OSSEC agent (must be run on both agent and server)
8 echo Usage: $0 old-name new-name
12 if ! [ -e /etc/ossec-init.conf ]; then
13 echo ossec-init.conf not found. Exiting...
17 . /etc/ossec-init.conf
18 KEYFILE=$DIRECTORY/etc/client.keys
20 # Get the IP address from the key file
21 IPADDR=`grep -w "${1}" $KEYFILE | cut -d " " -f 3`
22 if [ -z ${IPADDR} ]; then
23 echo Agent ${1} not found. Exiting...
28 /var/ossec/bin/ossec-control stop
30 # Update the key record
31 sed -i $KEYFILE -e "s/${1}/${2}/"
33 # Rename files and directories (manager)
37 if [ -e "agent-info/${1}-${IPADDR}" ]; then
38 mv "agent-info/${1}-${IPADDR}" \
39 "agent-info/${2}-${IPADDR}"
42 if [ -e "diff/${1}" ]; then
47 if [ -e "rootcheck/(${1}) ${IPADDR}->rootcheck" ]; then
48 mv "rootcheck/(${1}) ${IPADDR}->rootcheck" \
49 "rootcheck/(${2}) ${IPADDR}->rootcheck"
52 if [ -e "syscheck/(${1}) ${IPADDR}->syscheck" ]; then
53 mv "syscheck/(${1}) ${IPADDR}->syscheck" \
54 "syscheck/(${2}) ${IPADDR}->syscheck"
57 if [ -e "syscheck/.(${1}) ${IPADDR}->syscheck.cpt" ]; then
58 mv "syscheck/.(${1}) ${IPADDR}->syscheck.cpt" \
59 "syscheck/.(${2}) ${IPADDR}->syscheck.cpt"
63 /var/ossec/bin/ossec-control start