Shell scripting daily activities
The purpose of this is to simplify some of the daily routine for most system admins.These scripts go through a couple of the basics that we run into every day.. "My computer has a virus" "I forgot my email password" "X program isn't working.All of the commands are executed in the background using the WMI toolkit in linux. They have been extensively tested using winexe 0.90 on Ubuntu 8.04.Let me know what you think...
# For Daysol, Inc internal purposes only.# DO NOT DISTRIBUTE.# Author: Sean Sturts# Version 0.1# Confirmed working: 08/06/2010 16:40# Syntax: ./mgmt.sh# This script will allow an administrator to rename a restricted user# profile or reset a Zimbra email password.# This script depends on the WMI toolkit (apt-get install wmi-client) or it can be# build from source.choice=5# Print the selection menuecho "1. Rename User Profile"echo "2. Change Zimbra Password"echo "3. Turn off XP Firewall"echo "4. Exit"echo -n "Please select an action [1-4]: "while [ $choice -eq 5 ] ; doread choice# Choice 1.# This section of the script connects to the user pc using winexe and renames the# problematic profile.# The user name must be correct and the extension must be unique.if [ $choice -eq 1 ]; thenecho "Please enter the domain admin password [ENTER]: (text will not be displayed.)"stty -echoread PASSWORDstty echoechoecho -n "Please enter the username [ENTER]: "read USERNAMEechoecho -n "Please enter a unique extension [ENTER]: "read EXTENSIONechoecho -n "Please enter the client IP address [ENTER]: "read HOST_IP{winexe -U "Domain\username%$PASSWORD" //$HOST_IP \cmd <<EOF &shutdown -r -f -t 60 -c "The PC will be restarted in 60 seconds. The virus removal process may take up to 7 minutes"exitEOF}{sleep 8echoechoechoecho Press [ENTER] when the computer has restarted.read null}{winexe -U "Domain\username%$PASSWORD" //$HOST_IP \cmd <<EOF &cd \docu*rename $USERNAME $USERNAME.$EXTENSIONEOF}{sleep 5echoechoechoecho Press [ENTER] after the user has logged in.read null}{winexe -U "Domain\username%$PASSWORD" //$HOST_IP \cmd <<EOF &cd \docu*copy /Y $USERNAME.$EXTENSION\desktop $USERNAME\desktop\*.*copy /Y $USERNAME.$EXTENSION\favorites $USERNAME\favorites\*.*copy /Y $USERNAME.$EXTENSION\mydocu~1 $USERNAME\mydocu~1\*.*shutdown -r -f -t 15 -c "There is really no need for this restart but why not..."EOF}{sleep 20echoechoechoecho Process is complete.}breakelse# Choice 2# This section of the script connects to the Zimbra server using plink.# It executes a remote script for administrative prompts.if [ $choice -eq 2 ]; then{plink -l root -ssh 10.2.0.103 /root/./zimbrapwchange.sh}else# Choice 3# This script will turn off the Windows XP firewall and add port exceptions.# You must be able to ping the PC for this to work. This does not work on# SP3.if [ $choice -eq 3 ]; then{echo "Please enter the domain admin password [ENTER]: (text will not be displayed.)"stty -echoread PASSWORDstty echoechoecho -n "Please enter the client IP address [ENTER]: "read HOST_IPwinexe -U "Domain\username%$PASSWORD" //$HOST_IP \cmd <<EOF &netsh firewall add portopening all 5900 VNC_5900netsh firewall add portopening all 1000 Random_namenetsh firewall add portopening all 1001 Another_port# This portion of the script will remove the domain users group from the Administrators# group. This is not necessary.net localgroup "administrators" "Domain\domain users" /deleteexitecho "The process is complete."EOF}breakelse# Choice 4# Exit the script without making an administrative selection.if [ $choice -eq 4 ]; then{break}{# Print the selection menuecho "1. Rename User Profile"echo "2. Change Zimbra Password"echo "3. Turn off XP Firewall"echo "4. Exit"echo -n "Please select an action [1-4]: "choice=5}fifififidone##############################################################################################################################This is a seperate script that is accessed by the above script. It is seperate for ease of use..# For Daysol, Inc internal purposes only.# DO NOT DISTRIBUTE.# Author: Sean Sturts# Version 0.2.1# Date of revision: 8/5/2010 09:05# Confirmed working: 8/5/2010 09:15# Syntax: ./zimbrapwchange.sh# The purpose of this script is to automate changing user passwords in Zimbra OSS.# This section of the script prompts for user input.echo Please enter the Username and Domain. [ENTER:]read USERNAMEecho Please confirm the Username and Domain. [ENTER:]read CONFIRM## Commented for static password changes.# echo Please enter the temporary password. [ENTER:]# read PASSWORD## Above will be removed later.# This section of the script confirms the Username.if [ $USERNAME = $CONFIRM ]; thenecho The username was confirmed. Their password will be changed.# This section changes the users passwordsu - zimbra /opt/zimbra/bin/zmprov sp $USERNAME 123456# This section requires the user to change their password on first login.su - zimbra /opt/zimbra/bin/zmprov ma $USERNAME zimbraPasswordMustChange TRUE# Exiting script & terminating SSH sessionelseecho The username was not confirmed. Terminating.exitexitexitfiexitexitexit