Help with writing Shell Script to automate process using multiple commands

Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 06-02-2016
Help with writing Shell Script to automate process using multiple commands

Hello!

Need help to write a Linux script that can be run from windows using command/Cygwin/any other way. I am new to scripting, actually i am trying to automate server health check like free disk space, memory along with few services status, if any services is not running then start services , clear logs to resolve disk space issue. Script should store default user cgriffin with predefined password. fist check for 7 services then free disk space . If all services running then look for free disk space(if any service is not running then fnd out service whic is not running). Attached are commands thatw e manually run. Anybody who can help to automate this using shell script run using windows machine? Kindly help me
# 2  
Old 06-02-2016
First of all: Learn to Script

Above all I suggest you 2-3 tutorials in Shell-Scripting, so you get familiar with the necessary environment in order to be able to write the scripts, which are executing the necessary actions.

Here are some hints for an easy start:

Don't reinvent the wheel - use a monitoring system

My first thought is, that on every linux server that is managed this way a monitoring should be installed. This monitoring is configured for the relevant paramaters that your task needs. And if one the parameters is bad an action(e. g. a little script) should be executed, which fixes the situation.

Of course you do not need a monitoring system at all. You can script all the way through with your own scripts. But if you use a monitoring system it will be far more stable and feature rich than your own code, especially as you are now at the beginning to learn scripting.

The windows machine is of no use here - imho - because monitoring is nothing which must be started on demand. Monitoring is running always.

All major monitoring systems - by design big software packages to monitor many servers - can initiate custom actions on flexible defined failed checks. But those systems are very feature rich and so you need your time to get familiar with it and to learn how to use them. Pure Nagios is feared for its hell of config files.

Monit - a simple monitoring utility

A monitoring system which is far simpler than the other heavywheights is Monit and specially designed for simple monitoring and actions. I could imagine, that this would be the tool, that helps you most with your current task.

Check_MK

Personally I'm using check_mk - a full featured monitoring suite based on Nagios. I like it very much. And I recommend it if you have at least about 20-30 servers or more to monitor in detail - but of course "Server Monitoring" in whole is not your task. And of course I'm triggering a bunch of maintenance actions to fix various server problems.

Use an existing monitoring system?

Maybe your environment has already a monitoring suite( I suppose not ), which you can use to trigger the needed actions? Ask your colleagues!

Update-1

Maybe some simple cronjobs run once a day or once a week can help you too.

Last edited by stomp; 06-03-2016 at 11:12 AM..
This User Gave Thanks to stomp For This Post:
MadeInGermany (06-03-2016)
# 3  
Old 06-03-2016
I'm pretty sure that people participate in here "who can help to automate" although mayhap NOT with windows machines. Still I doubt they want to infer the bits and pieces from a rough and ready log of what is normally done manually.

Please take the trouble to prepare a correct specification, defining a (or multiple?) precise target(s), show the underlying basic data, structures, and OS/tools, possible restrictions, and your own ideas how to connect the two.
# 4  
Old 06-03-2016
First of all: Learn to Script

Hi Stomp, first of all i need to say is appreciate your quick reply.Than You.


Sure! I will try to use Monit and Check_MK both

We already have zabbix monitoring tool for all server in our datacenter, these servers what i am trying to automate health check are staging servers where our product will be tested before deploying to production environment, some time while testing Dev team may get errors due to stopped services, low disk space etc so that time they will contact IT to look into issue and resolve. For now we manually doing this Job as IT admin, i am trying to automate this work to make less effort to resolve the issue. These servers are in near 50-60 Cnetos 5.8 servers running squid, puppet for other our product testing reasons.

like i have wrote a powershell script, when i run script it prompts for server name (manually need to eneter) then it automatically display free disk space, CPU usage , memory usage ect in browser in some specific format. It reduces manually logging to server and checking everything one by one. Same way in need to do for linux server.

Anyway will try to implement Monit and Check_MK right away and let you know the result meanwhile after more explanation about my requirement if you have any other solution then please share with me.


Thanks
# 5  
Old 06-03-2016
Isn't it much easier to add them to zabbix and set a service outage or a special notification group?
# 6  
Old 06-03-2016
Yes. I recommend too to use zabbix. You may get help from your colleagues, which have already probably good knowledge handling it. Using zabbix now helps you to work with it with your production servers too. And at least no one would like to have the complexity multiple different monitoring systems if there's no need for it.

Maybe it's a good option to set up a zabbix instance for your own. So you do not kill the production monitoring system if configuration errors occur. If you get all up and running at your test site, you may migrate your rules from test to production monitoring system.
# 7  
Old 06-03-2016
OK will try to setup Zabbix, if i need help then will Reply to thread. Stomp or anyone else If good in zabbix then please help.

Thanks everyone for your suggestions!

---------- Post updated at 03:53 PM ---------- Previous update was at 03:02 PM ----------

Those staging servers are already available/configured in Zabbix server (CPU,Disks,Filesystem, Memory). But for services there is no configuration like squid, puppet etc also from zabbix alerts we will only come to know the problem then again we need to login to the server to fix the issue. What i am looking for is just login to server for which issue is reported and run a script that automatically check for 7 services status, if any one is down then prompt for restart, else next step check free disk space if space is less then there is command to check top 50 folders using space run that and see in that folder if any of 7 services logs folder are listed if yes then go to every logs run command delete it finally end the script. Is possible to write such script ? please help

---------- Post updated at 03:56 PM ---------- Previous update was at 03:53 PM ----------

please refer attached file for commands/services that we use to do logs cleanup(Automate Linux Commands)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Check status of long running multiple curl commands in shell script oraclermanpt Shell Programming and Scripting 2 2 Weeks Ago 04:11 AM
Shell script replied multiple process for file has successfully created yogendra.barode Shell Programming and Scripting 3 12-28-2015 07:03 AM
Script to automate recovery process RogerBaran Shell Programming and Scripting 3 05-21-2015 11:14 AM
How to catch errors in a shell script ( multiple commands )? bobochacha29 Shell Programming and Scripting 3 05-04-2015 04:25 AM
Help with writing a script to run java commands in sequence in UNIX Wixaros Shell Programming and Scripting 3 02-11-2015 02:01 PM
Automate sftp process using script warmboy610 UNIX for Dummies Questions & Answers 3 07-26-2013 03:22 AM
Automate multiple commands gecko1 Shell Programming and Scripting 4 06-03-2013 02:07 AM
Need help in creating a shell script to automate svnstats process d8011 Shell Programming and Scripting 0 05-28-2012 03:41 AM
Writing a loop to process multiple input files by a shell script evelibertine UNIX for Dummies Questions & Answers 4 10-11-2011 06:14 PM
Bash script to Automate the Virtual Host creation process!! anishkumarv Shell Programming and Scripting 5 07-12-2011 07:25 AM
writing a shell script of commands rahul_11d Shell Programming and Scripting 1 06-01-2009 04:42 AM
Error in script to automate the daily monitoring process of UNIX server and it's proc rdhaprakasam Shell Programming and Scripting 8 04-21-2009 11:05 AM
writing shell scripts of commands rahul_11d Shell Programming and Scripting 0 03-09-2009 12:20 PM
Automate Script using pkgrm/pkgadd commands Insight UNIX for Advanced & Expert Users 13 09-26-2008 08:21 AM
Shell script to call multiple java commands vivekdn Shell Programming and Scripting 4 09-03-2008 01:28 AM