清理脚本

清理脚本

 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=$'\n'
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 您可以使用PowerShell脚本清理磁盘空间。 下面是一个简单的脚本,可以帮助您轻松清理磁盘: $drives = Get-PSDrive -PSProvider FileSystem foreach ($drive in $drives) { Clean-Item -Path $drive.Root -Recurse -Force } ### 回答2: PowerShell是一种用于自动化任务和管理系统的脚本语言,它可以帮助我们编写磁盘清理脚本以释放磁盘空间。下面是一个简单的示例: ```powershell # 设置要清理的目录路径 $targetPath = "C:\Temp" # 获取目录中的文件列表 $files = Get-ChildItem -Path $targetPath # 设置最大文件大小限制(单位:MB) $maxFileSize = 100 # 遍历文件列表,删除过大的文件 foreach ($file in $files) { if ($file.Length -gt ($maxFileSize * 1MB)) { Remove-Item $file.FullName -Force Write-Output "已删除文件: $($file.FullName)" } } # 清理完成后显示释放的磁盘空间大小 $freedSpace = ($files | Where-Object { $_.Length -gt ($maxFileSize * 1MB) } | Measure-Object -Sum Length).Sum Write-Output "已释放磁盘空间: $([Math]::Round($freedSpace / 1GB, 2))GB" ``` 以上脚本首先定义了要清理的目录路径(此处为C:\Temp),然后使用`Get-ChildItem`命令获取该目录中的文件列表。接下来,我们设置了一个最大文件大小限制(此处为100MB),遍历文件列表,并删除超过限制大小的文件。同时,脚本会输出删除的文件路径。 最后,脚本会计算释放的磁盘空间大小,并输出。这样,我们就可以通过运行这个PowerShell脚本清理指定目录下的过大文件,释放磁盘空间。 ### 回答3: Powershell磁盘清理脚本是一段编程脚本,用于帮助用户清理计算机硬盘上的不需要的文件和数据。它可以自动删除临时文件、日志文件、回收站中的文件以及其他占用磁盘空间的无用文件。 这个脚本使用Powershell语言编写,Powershell是一种微软开发的脚本语言,可以在Windows系统上运行。运行脚本之前,用户需要确保已经安装了Powershell,并且具有管理员权限。 磁盘清理脚本可以根据用户的需求进行灵活的配置。用户可以选择要清理的文件类型,例如临时文件、日志文件、浏览器缓存等。脚本还可以删除较旧的文件,以便为新文件腾出更多的磁盘空间。 此外,磁盘清理脚本还可以定期运行,以便自动保持计算机的磁盘空间清理。用户可以使用Windows任务计划程序将脚本设置为每天、每周或每月运行一次,以确保计算机的磁盘始终保持清理状态。 总的来说,Powershell磁盘清理脚本是一种有效的工具,可帮助用户自动化计算机磁盘空间的管理。通过删除无用的文件,它可以确保计算机的磁盘空间始终保持在适当的水平,提高计算机的性能和效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值