最近遇到了一个问题,就是python代码调用shell脚本时,发现输入输出的文件,总是和自己预想的有偏差,但是单独在linux下执行命令的时候,却没有错误.后来发现是相对路径的问题,因为执行python文件的时候,会有一个工作目录,而执行shell脚本的时候,又会有一个工作目录,这样就很容易混淆.最好的办法:在执行shell脚本时,将目录切换到shell脚本下: cmd = '/home/usr/asdasd/' os.system(cmd) 这样问题就解决了.…
本文我们介绍一个shell脚本,用来使用rsync命令将你本地Linux机器上的文件/目录备份到远程Linux服务器上.使用该脚本会以交互的方式实施备份,你需要提供远程备份服务器的主机名/ip地址和文件夹位置.我们使用一个单独的列表文件,在这个文件中你需要列出要备份的文件/目录.我们添加了两个脚本,第一个脚本在每次拷贝完一个文件后询问密码(如果你启用了ssh密钥验证,那么就不会询问密码),而第二个脚本中,则只会提示一次输入密码. 我们打算备份bckup.txt,dataconfig.txt,do…
1.这是很简单的一个 文件监控+触发同步脚本 监控一台服务器下的一个文件夹,发生改变则向另一个个文件夹进行同步. 具体的inotify命令  rsync命令  可以看linux分类下的介绍 inotify:https://www.cnblogs.com/centos2017/p/7896715.html rsync: https://www.cnblogs.com/centos2017/p/7896702.html #!/bin/sh SRC=/var/www/channel/ DST=/var…
一.统计单台机器 /home/ 目录下磁盘空间使用 top3 的用户 common.sh 脚本用于统计 /home/* 目录下存储空间 top3 的用户. du -sb /home/* |sort -nr |head -n 3 #单位为B 二.统计分析多台分布式机器上 /home/ 目录用户磁盘使用情况 #!/bin/sh # set -x # 打印执行过程 SUBMIT_NODES="submit_nodes.txt" RESULT="result.txt" RE…
[root@backup ~]# vim /etc/init.d/rsync#!/bin/bash #this script for start|stop rsync daemon service status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') pidfile="/var/run/rsyncd.pid" start_rsync="rsync --daemon…
[root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件 dir=/root/wyb/test10/ [ ! -d $dir ] && mkdir -p $dir ` do -`_oldboy.html done [root@localhost wyb]# bash test10.sh [root@localhost wyb]# cd tes…
#!/bin/bash # cd /etc for a in *;do if [ -L $a ];then #如果文件存在,为软链接文件且指向的是文件,则返回真 echo $a fi done 测试:…
第一种方法是通过cmp来进行比对[root@localhost bo]# ls .html .html .html .html .html .html .html .html .html cat.sh [root@localhost bo]# cat cat.sh #!/bin/bash [ ! -f /root/wyb/bo/cat.log ] && cat *.html > /root/wyb/bo/cat.log cat *.html >tmp.log cmp tmp.l…
#!/bin/bash dir=`ls /root//*` for i in $dir do #basename 返回一个字符串参数的基本文件名称.(只剩下文件名除去路径名) a=`basename $i` cd /root// r=`find . -name "$a"` if [ "$r"x == "./$a"x ]; then continue else scp -r $i root@ fi done…
#!/bin/sh cd /home/test for i in `ls -l |awk '{if($5>10240) {print $9}}'` do mv $i /tmp done…