清理脚本

清理脚本

 1 #!/bin/sh
 2 
 3 rm -rf /etc/crontab
 4 echo "SHELL=/bin/bash">>/etc/crontab
 5 echo "PATH=/sbin:/bin:/usr/sbin:/usr/bin">>/etc/crontab
 6 echo "MAILTO=root">>/etc/crontab
 7 echo "HOME=/">>/etc/crontab
 8 echo "">>/etc/crontab
 9 echo "# For details see man 4 crontabs">>/etc/crontab
10 echo "">>/etc/crontab
11 echo "# Example of job definition:">>/etc/crontab
12 echo "# .---------------- minute (0 - 59)">>/etc/crontab
13 echo "# |  .------------- hour (0 - 23)">>/etc/crontab
14 echo "# |  |  .---------- day of month (1 - 31)">>/etc/crontab
15 echo "# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...">>/etc/crontab
16 echo "# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat">>/etc/crontab
17 echo "# |  |  |  |  |">>/etc/crontab
18 echo "# *  *  *  *  * user-name command to be executed">>/etc/crontab
19 chmod 644 /etc/crontab
20 ps -ef | grep jdk | awk '{print $2}'| xargs kill -9
21 ps -ef | grep tomcat | awk '{print $2}'| xargs kill -9

删除脚本

 1 #!/bin/sh
 2 # clean bigdata services
 3 
 4 CLUSTER_NUM=`ls /usr/lib/cloudmanager/components/lark/data/clusters/ | wc -l`
 5 
 6 # single mode
 7 if [ $CLUSTER_NUM == 1 ]
 8 then
 9   sh ps-kill.sh
10   rm -f /etc/rc.d/init.d/keepalived
11   if [ -f '/opt/PostgreSQL/9.2/uninstall-postgresql' ]
12   then
13     /opt/PostgreSQL/9.2/uninstall-postgresql --mode unattended
14     rm -f /etc/rc.d/init.d/postgresql-9.2
15     rm -rf /opt/PostgreSQL
16     rm -rf /opt/pgpool
17   fi
18   rm -rf /mnt/disk*/*
19   rm -rf /mnt/ssd*/*
20   rm -rf /tmp/*
21   rm -rf /usr/lib/cloudmanager/components/lark/data/clusters/LOCALCLUSTER
22 # distributed mode
23 elif [ $CLUSTER_NUM -gt 1 ]
24 then
25   NODES=`cat /etc/hosts|grep -v -E 'localhost|mirrors'|awk '{print $2}'`
26   for cluster in `ls /usr/lib/cloudmanager/components/lark/data/clusters/ | grep -v LOCALCLUSTER`
27   do
28     for node in ${NODES[@]}
29     do
30       scp -p ps-kill.sh $node:/root
31       ssh $node "/root/ps-kill.sh"
32       ssh $node "/root/ps-kill.sh"
33       ssh $node "rm -rf /etc/${cluster}"
34       ssh $node "rm -rf /usr/lib/${cluster}"
35       ssh $node "rm -rf /var/log/${cluster}"
36       ssh $node "rm -rf /var/run/${cluster}"
37       ssh $node "rm -rf /etc/rc.d/init.d/${cluster}"
38       ssh $node "rm -f /etc/init.d/keepalived"
39       ssh $node "rm -f /etc/rc.d/init.d/postgresql-9.2"
40       ssh $node "rm -rf /opt/PostgreSQL"
41       ssh $node "rm -rf /opt/pgpool"
42       ssh $node "rm -rf /mnt/disk*/*"
43       ssh $node "rm -rf /mnt/ssd*/*"
44       ssh $node "rm -rf /tmp/*"
45       ssh $node "rm -rf /usr/lib/cloudmanager/components/lark/data/clusters/${cluster}"
46     done
47   done
48 fi
49 # clean LOCALCLUSTER directories for any mode
50 rm -rf /etc/LOCALCLUSTER
51 rm -rf /usr/lib/LOCALCLUSTER
52 rm -rf /var/log/LOCALCLUSTER
53 rm -rf /var/run/LOCALCLUSTER
54 rm -rf /etc/rc.d/init.d/LOCALCLUSTER*

代替文本脚本

 1 #!/bin/bash
 2 
 3 #hosts old -> new
 4 #      old -> new 
 5 #      old -> new
 6 echo "=================================="
 7 echo "===plz exec the shell in the 001 node====="
 8 echo "在001节点执行此脚本"
 9 echo "=================================="
10 IFS=$'
'
11 echo $#
12 if(( "$#" < 3))
13 then
14  echo "plz input the hosts file name , the clustername, the nginx name"
15 else
16  file=$1
17  clustername=$2
18  nginxname=$3
19  echo $file
20  echo $clustername
21  echo $nginxname
22  /usr/lib/cloudmanager/components/lark/bin/lark shell -c services.stop $2 $3
23  for line in `cat $1`;
24  do
25   newIp=${line#* }
26   oldIp=${line% *}
27   echo "line=$line old=${oldIp} new=${newIp}"
28   for line in `cat $1`;
29     do
30       newIp2=${line#* }
31       oldIp2=${line% *}
32       `ssh $newIp "sed -i "s/$oldIp2/$newIp2/g" /etc/hosts"`
33       `ssh $newIp "sed -i "s/$oldIp2/$newIp2/g" /usr/lib/cloudmanager/components/webui/webapps/cm/model/conf.json"`
34       `ssh $newIp "sed -i "s/$oldIp2/$newIp2/g" /usr/lib/cloudmanager/components/lark/data/clusters/LOCALCLUSTER/cluster.yml"`
35       `ssh $newIp "sed -i "s/$oldIp2/$newIp2/g" /usr/lib/cloudmanager/components/lark/data/clusters/$2/cluster.yml"`
36       `ssh $newIp "sed -i "s/$oldIp2/$newIp2/g" /etc/$2/SERVICE-KAFKA-*/server.properties"`
37       `ssh $newIp "sed -i "s/$oldIp2/$newIp2/g" /etc/$2/SERVICE-ZOOKEEPER-*/zoo.cfg"`
38       `ssh $newIp "sed -i "s/$oldIp2/$newIp2/g" /etc/$2/SERVICE-ELASTICSEARCH-*/elasticsearch.yml"`
39     done
40  done
41 fi
原文地址:https://www.cnblogs.com/jinniezheng/p/6397555.html