delete

Shell Script – Server Maintenance

So here’s my first shell script, written for a server at work who has maintenance tasks that need to be completed, and the commands get tedious to input and remember, now all you have to remember is ./maintenance

The script automates 4 tasks that our server has. Restarting out PostgreSQL database, restarting apache, vacuuming the database, and running our custom import scripts, which has to be done as a specific user each day, and NOT as root… which has caused issues in the past, but now if you run them with the script I wrote, there’s no issue at all.

When launched, the script displays a menu for you, on which you make your choices.

scriptmenu

You can then make your choice, via number, and it will complete the task and prompt you to continue.
When a wrong choice is made it tells you that you need to select a number from the list. The help command gives you an idea of what each other command does, and exit obviously exits the script.

So here’s a video to demonstrate how the menu system works.

Its a simple shell script, but it works, and it works well for what it does.
And of course I’d want to share the actual script with you, and document it in my blog,
so here it is, Frank’s maintenance script!

#######################################################
#  _______        _            _                      #
# |__   __|      | |          | |                     #
#    | | ___  ___| |__        | | __ ___      ____ _  #
#    | |/ _ \/ __|  _ \   _   | |/ _` \ \ /\ / / _` | #
#    | |  __/ (__| | | | | |__| | (_| |\ V  V / (_| | #
#    |_|\___|\___|_| |_|  \____/ \__,_| \_/\_/ \__,_| #
#                                                     #
#           www.techjawa.com/category/code            #
#             www.corey.degrandchamp.com              #
#                                                     #
#######################################################
#                                                     #
# Written  By: Corey DeGrandchamp                     #
# Written  On: June 18, 2009                          #
# Written For: Michigan Drill Corporation             #
# Description: This shell script will automate all of #
#              the maintenance tasks on Frank.        #
#                                                     #
#######################################################
#                                                     #
# Edit   Date: June 24, 2009                          #
# Edit     By: Corey DeGrandchamp                     #
# About  Edit: Fixed script so the heading/title will #
#              show every time now, also made it      #
#              pause and wait for the ENTER key to    #
#              be pressed before it continues.        #
#                                                     #
#######################################################

#!/bin/bash

# Display the title.
clear
echo '
     __  __    __    ____  _  _  ____  ____  _  _    __    _  _  ___  ____
    (  \/  )  /__\  (_  _)( \( )(_  _)( ___)( \( )  /__\  ( \( )/ __)( ___)
     )    (  /(__)\  _)(_  )  (   )(   )__)  )  (  /(__)\  )  (( (__  )__)
    (_/\/\_)(__)(__)(____)(_)\_) (__) (____)(_)\_)(__)(__)(_)\_)\___)(____)

	'
# Display possible choices.
CHOICES="RESTART_POSTGRESQL RESTART_APACHE VACUUM_DATABASE RUN_IMPORTS HELP EXIT"
# Define commands for choices.
select choice in $CHOICES; do
	if [ "$choice" = "RESTART_POSTGRESQL" ]; then
		/etc/rc.d/init.d/postgresql restart
		echo ""
		echo ""
		echo ""
		echo ""
		echo "Finished restarting PostgreSQL."
		echo ""
		echo "Press ENTER to continue."
		read
		clear
	elif [ "$choice" = "RESTART_APACHE" ]; then
		service httpsd restart
		echo ""
		echo ""
		echo ""
		echo ""
		echo "Finished restarting Apache."
		echo ""
		echo "Press ENTER to continue."
		read
		clear
	elif [ "$choice" = "VACUUM_DATABASE" ]; then
		su ********-c "/usr/bin/vacuumdb -* *******"
		echo ""
		echo ""
		echo ""
		echo ""
		echo "Finished vacuuming the database."
		echo ""
		echo "Press ENTER to continue."
		read
		clear
	elif [ "$choice" = "RUN_IMPORTS" ]; then
		su ********-c "/home/********/********/********/IMPORT"
		echo ""
		echo ""
		echo ""
		echo ""
		echo "Finished running the imports."
		echo ""
		echo "Press ENTER to continue."
		read
		clear
	elif [ "$choice" = "HELP" ]; then
		clear
		echo "RESTART_POSTGRES"
		echo "     - Useful for when SOEFIE giving errors, or functioning slowly."
		echo ""
		echo "RESTART_APACHE"
		echo "     - When changes are made to websites, or websites are not working."
		echo ""
		echo "VACUUM_DATABASE"
		echo "     - This will vacuum the veritime database, clearing our all of the junk."
		echo ""
		echo "RUN_IMPORTS"
		echo "     - Runs the imports from the AS/400 to SOEFIEs database."
		echo ""
		echo "HELP"
		echo "     - Displays this menu"
		echo ""
		echo "EXIT"
		echo "     - Exits the program."
		echo ""
		echo ""
		echo ""
		echo ""
		echo "Press ENTER to continue."
		read
		clear
	elif [ "$choice" = "EXIT" ]; then
		clear
		exit
	else
		echo ""
		echo ""
		echo ""
		echo ""
		echo "Please choose a number from the list."
		echo ""
		echo "Press ENTER to continue."
		read
		clear
	fi
# Display the title after each choice again.
	echo '
     __  __    __    ____  _  _  ____  ____  _  _    __    _  _  ___  ____
    (  \/  )  /__\  (_  _)( \( )(_  _)( ___)( \( )  /__\  ( \( )/ __)( ___)
     )    (  /(__)\  _)(_  )  (   )(   )__)  )  (  /(__)\  )  (( (__  )__)
    (_/\/\_)(__)(__)(____)(_)\_) (__) (____)(_)\_)(__)(__)(_)\_)\___)(____)

	'
done

Some parts taken out to protect our security….

I know there are other ways to do what I achived here, but as I said before, this is my VERY FIRST shell script.


delete

AS/400 Problems

computer_on_fireWell I’ve been trying to work on creating a new report, but there are problems getting data out of the AS/400… I’ve been working on this for 8 hours a day for the past two days straight, and I can already tell it’s going to be another 8 hours tomorrow again.

Bob Branch wrote a script to fetch files from the AS/400, and convert them into a CSV file, and we open it in Excel, and format the reports, keeping the information that we need. Problem is… is that aparrently this information is incorrect. We need to come up with a report of all the inventory that hasn’t sold in one year… I did that, but aparrently there are some pieces that Republic has sold… but we have not, and Republic maybe sold one or two, and it’s still showing as zero sold. This is a problem, and needs to be fixed ASAP.

So far I have tried editing the “get” script on Frank to ONLY fetch files from MDNorth AS/400, as it still contains the RDC history files, but that didn’t fix anything, and we ended up with the exact same result…

Trying some more script editing tomorrow I suppose. The bank needs this ASAP.


delete

Conficker: Likely CLEAN

Well, with April 1st fast approaching, and the deadly “Conficker” virus that everybody’s been so stressed about right around the corner… I thought it was necessary to take action today.

In case you don’t know, the Conficker virus is something nearly undetectable, and its sitting dormant across millions of computers world wide, waiting for a digitally-signed command from a central location on April 1st. I know it seems like an April fools day joke, but who knows what could happen. The virus can’t be disabled by falsely giving it a command to shut down, since it only accepts signed code for the correct source.

conficker_clean

Anyhow, the nmap team discovered a way of detecting it across the network earlier this morning… just in time I know. I made sure I did a scan, and after a while of figuring out exactly HOW to do the correct scan, our results came back as CLEAN here at Michigan Drill. This means no worrying for [at least] our location.

dreamstime-virusI however assume we’re all safe in the matter.

I must say… I’m curious to know what this particular worm actually is going to do tomorrow to those who ARE infected… >_>






Powered by WP VideoTube