Shell再学习 规格严格

1、http://blog.csdn.net/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/p/2446445.html