linux后台传送图片脚本

来源:互联网 发布:openstack源码安装 编辑:程序博客网 时间:2024/05/14 07:19

感谢百度知道的小米飞猫,很热心。

#!/bin/bash 
stip="192.168.220.10" 
un="root" #账户
fw="123" #密码 
local_dir="/home/ango/images/" #本地路径 
s_dir="/home/ango/images/" #远程路径 
cd $local_dir #进入本地目录 
while true;do #开始循环 
file_jpg=(`ls *.jpg 2>/dev/null`) 
if [ -z $file_jpg ];then
        sleep 1 #这个地方加个sleep吧
        continue
else
        for file in ${file_jpg[*]};do
                scp $file ${un}@${stip}:${s_dir}
        if [ $? -ne 0 ];then
                continue
        fi
        rm -f $file && sleep 1
        done
fi
done

放在后台执行

nohup ./test.sh  >/dev/null 2>&1 &

先敲下面两个命令,ip是远程机器地址,username就是用户名,必须有远程机器图片目录的写和执行权限。ssh-keygen -t rsa一路回车 ssh-copy-id username@ip以上是让远程机器对本机信任,以后不要密码直接ssh如果是在前台调试 脚本 
可以用 ctrl+c 终止,如果是 后台运行的, ps -ef | grep 脚本名称 ,根据查出来的进程号  直接 kill -9 进程号就好了



原创粉丝点击