Shell再学习

1、http://blog.youkuaiyun.com/chinalinuxzend/article/details/2403613

 

最近项目又要求写shell脚本完成相应升级工作,无奈,这工作又落在我脑袋上,于是我还得在学习学习。

 

添加一段测试时间戳的简单脚本:


#Ghetto auto SCP script Bryan Encina 10-16-2003  

#Assumptions:    passwordless SCP has been setup via generation of private/public 
#        keypair and insertion of pub key to webhost user's  
#        .ssh/authorized_keys file 
#Intended  Use:  uploading webcam image from linux server to another webhost 
#        that does  not support FTP (only SCP), probably of no  use to anyone  else 
#Usage:        make an entry in your crontab to  run as the user who's setup  for passwordless scp 
#        to  run this script with the  path to your webcam img as a  
#         command line arg         

#user settings edit the vars below 
checkduration=300          # if current - timestamp is less than this we have a new file default to 5 minutes 
remoteuser=myremoteuser    #user at remote host 
mydomain=mydomain.com    #the domain/ip of your remote host 
destpath=yourfile        #the  path to your remote file 

# do  not edit below unless you know what you're doing, but  if you did you  
#wouldn't be using this and you'd be writing your own wouldn't you? 
localfile=$1 

cur_timestamp=` date +%s` 
my_stat=`stat -t $localfile 2>/dev/null` 
read name size blocks unk uid gid dev inode links unk2 unk3 last_access last_mod last_change ioblock << ENDHERE 
    $( echo $my_stat) 
ENDHERE 

if [ $last_mod ] 
then 
    time_diff=`expr e$cur_timestamp - $last_mod` 
     if [ $time_diff -lt $checkduration ] 
     then     
        # echo This is a recent file 
        scp $localfile $remoteuser@$mydomain:$destpath 
    fi 
fi  

 

转载于:https://www.cnblogs.com/diyunpeng/archive/2012/04/13/2446445.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值