I’m now in charge of about 70 vps.Every vps has www web-server & proftpd ftp server & mysql db server on it.Now I want to know every server’s status.There’s of course method that notify you waking up at mid-night and handling with the simple reboot of apache & mysql & proftpd,yes,that’s true,for your boss won’t be happy enough to see all sites offline on servers that are within your duty.This is called a ‘pull’ working style.Ok.Now why don’t we try the ‘push’ working style now?Just write the following script on your server,and add it to the cron schedule at a proper execution rate.
The bash script auto-detect and monitor status of your service on a server,and if it find that the software has stopped working,the script will actively start it.And,if the number of httpd or mysqld exceeds the point you set in the script,the server will restart.All of this primarily should be your working scope,and now it’s all the bash script’s duty! Read more…
Another imagination:
You have 100 servers.Now you’ve got a task.The boss needs to create a directory under /root and put some files under it.
What would you do next?Just be honestly and sincerely and start log in ssh then use mkdir to create directory,then use sftp or even ftp to put the files under the directory?
That would tire you so much,sour you hands and mind.Now let one line bash shell script to help you.
Here goes the general idea about the solution:
1.Write a bash script with multiple parameters.Each two of the parameters match the ip address and password to your ssh root account.
2.Now the script runs.It auto get the two parameters as a pair,and use expect to auto answer to interactive output of ssh command(‘yes’ to ‘Are you sure you want to continue connecting (yes/no)?’,and your password parameter to ‘[email protected]’s password:’).
3.After log in the remote server using ssh,the script download a script from url you designate.Like http://yourblog.com/mkdir_and_put_files_in_it.sh.After the download,use ‘sh ./mkdir_and_put_files_in_it.sh’ to run it which has command ‘mkdir’ and ftp get in it. Read more…
Imagine,you’ve got a task now to verify a bulk of domains the speed of response and whether they are active or not.Here a bulk of,means,for example,1,000.On getting this task,what will you do next?Type in every ip in the command line in Microsoft’s cmd and waits for the result?1,000,you must consider it.You may imagine,how tired after you’ve pinged the full 1,000 of the urls.
Here is my implement of the task.Firstly,put the urls in domain.txt,one url per line.Then run the script:sh if.sh.Lastly,waits for the result in ip.txt.During the execution time,you may go out and breath fresh air or have a cup of tea,not type in the Microsoft cmd any more! Read more…