常用shell命令操作
2017-08-23 10:58
567 查看
1.判断2个目录同时存在再执行shell命令
#!/bin/bash
TestPath="/volume01/edit_high/"
TestPath1="/volume01_bak/edit_high/"
if [ -d "$TestPath" ]&&[ -d "$TestPath1" ]; then
echo "Ok";
rsync -a --delete /volume01/* /volume01_bak/
fi
2.在多个目录中查找超过7天的文件
#!/bin/bash
delfile()
{
find $i -type f -mtime +7 -print
}
Dirlist="/VMS_transfer/cztvcloud/mixiu_new/complete /VMS_transfer/cztvcloud/shixian_new/complete /VMS_transfer/cztvcloud/channel_new
/complete"
for i in $Dirlist;do
[ ! -z $i ] && delfile;
Done
3.从文本中读取IP地址,并修改密码,前提服务器免密码登陆。
cat iplist
192.168.122.3
192.168.122.4
192.168.122.5
# cat chpass.sh
#!/usr/bin/env bash
while read line
do
echo "------------- $line --------------"
ssh $line -n "echo '123456' | passwd --stdin root"
if [ $? -eq 0 ];then
echo "$line sucess."
else
echo "$line failed."
fi
done < iplist
另外方法:for i in `cat user.txt`; do useradd $i; done
4.除/home/dmtsai目录外,/home和/etc目录的所有东西都打包?
tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
tar -cvf /root/backup/`date+%y%m%d`_etc /etc 带时间的备份文件
#!/bin/bash
TestPath="/volume01/edit_high/"
TestPath1="/volume01_bak/edit_high/"
if [ -d "$TestPath" ]&&[ -d "$TestPath1" ]; then
echo "Ok";
rsync -a --delete /volume01/* /volume01_bak/
fi
2.在多个目录中查找超过7天的文件
#!/bin/bash
delfile()
{
find $i -type f -mtime +7 -print
}
Dirlist="/VMS_transfer/cztvcloud/mixiu_new/complete /VMS_transfer/cztvcloud/shixian_new/complete /VMS_transfer/cztvcloud/channel_new
/complete"
for i in $Dirlist;do
[ ! -z $i ] && delfile;
Done
3.从文本中读取IP地址,并修改密码,前提服务器免密码登陆。
cat iplist
192.168.122.3
192.168.122.4
192.168.122.5
# cat chpass.sh
#!/usr/bin/env bash
while read line
do
echo "------------- $line --------------"
ssh $line -n "echo '123456' | passwd --stdin root"
if [ $? -eq 0 ];then
echo "$line sucess."
else
echo "$line failed."
fi
done < iplist
另外方法:for i in `cat user.txt`; do useradd $i; done
4.除/home/dmtsai目录外,/home和/etc目录的所有东西都打包?
tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
tar -cvf /root/backup/`date+%y%m%d`_etc /etc 带时间的备份文件
相关文章推荐
- Shell命令之Android及iOS常用操作命令
- shell常用操作命令系列:服务操作
- HBase的Shell常用的操作命令
- hadoop 创建用户及hdfs权限,hdfs操作等常用shell命令
- shell常用操作命令系列:软件操作命令
- 常用的Shell命令:重启tomcat,打包,移动,等其他操作较多的命令
- hadoop 创建用户及hdfs权限,hdfs操作等常用shell命令
- hadoop 创建用户及hdfs权限,hdfs操作等常用shell命令
- shell常用操作命令系列(软件操作命令)
- hadoop 创建用户及hdfs权限,hdfs操作等常用shell命令
- Linux Shell 常用shell命令(一)文件、目录操作命令
- 1、shell指令操作【ubuntu】 - 常用shell命令
- 常用的Shell命令-目录和文件操作
- Centos Linux 常用shell操作命令
- linux中shell常用联合批量操作命令
- mondodb常用shell命令和常用java驱动操作
- MongoDB mongo shell,常用的操作命令,GUI客户端
- linux bash shell常用文件操作命令
- hadoop 创建用户及hdfs权限,hdfs操作等常用shell命令