分类 默认分类 下的文章

bash:rsync自动反复重试脚本,直到执行成功,/v/bin/rsync-retry

#/bin/bash
#rsync自动重试warp;直到成功
SCRIPTPATH=$(realpath $0)
display_usage() {
    echo -e "$SCRIPTPATH\n"
    echo -e "\trsync自动重试脚本,rsync执行失败后重新运行命令,可指定最大重试次数和重试间隔时间;"
    echo -e "\t参数一即失败重试次数,可省略,缺省次数为-1,默认反复执行直到返回成功."
    echo -e "\t参数二即周期延时时间,可省略,缺省参数为20,即间隔20s进行下一次循环调用."
    echo -e "\nUsage:\n\trsync-retry [max-try-times] [delay-seconds-time] rsync~options~~"
    echo -e "Example:\n\trsync-retry 10 20 -rlvvzPD --size-only --bwlimit ./ winhk:/root/files/"
}
# if less than two arguments supplied, display usage
if [  $# -lt 1 -o "$*" == "-h" ]
then
    display_usage
    exit 1
fi

# check whether user had supplied -h or --help . If yes display usage
#if [[ ( $# == "--help") ||  $# == "-h" ]]
if [[ ( $* == "--help") ||  $* == "-h" ]]
then
    display_usage
    echo -e "\n-------------------------------------------------\n"
    #exit 0
fi

#Option:默认重试次数
retry_time=-1

#判断第一个参数是否为纯数字,如果是数字,则认定为命令最大重试次数
expr $1 "+" 10 &> /dev/null  
if [ $? -eq 0 ];then
retry_time=$1
shift
fi

##空格路径文件处理
#IFS=$(echo -en "\n\b")

#Option:默认延时
delay_time=20

#判断第二个参数是否为纯数字,如果是数字,则认定为重复调用命令的间隔时间
expr $1 "+" 10 &> /dev/null  
if [ $? -eq 0 ];then
delay_time=$1
shift
fi

return_val=-1
run_time=0
while [ "$return_val" -ne 0 -a "$retry_time" -eq "-1" ] || [ "$return_val" -ne 0 -a "$run_time" -lt "$retry_time" ]
do
#只有指定有限次的(具体数值)运行次数时,程序才计算命令当前累计调用的次数
if [ "$retry_time" -ne "-1" ];
then 
let run_time+=1
fi
rsync $*
return_val=$?
if [ "$retry_time" -ne "-1" ];
then
echo -e "\t第 ${run_time} 次返回值:${return_val}  (${run_time}/${retry_time})\n"
fi
## 如果是最后一次调用或者此次调用命令返回成功值,则不进行延时
if [ ${run_time} -ne ${retry_time} ] && [ ${return_val} -ne 0 ];then
#重试延时,默认为20s,不需要可以注释掉,最好适当增加延时,哪怕一秒也OK,0延时可能导致Ctrl + C无法中断指令。
sleep ${delay_time}
fi
done

echo -e "\t命令序列执行完毕..."

扫描二维码,在手机上阅读!

【FTP便携文件助手】,bat使用lftp便携上传文件到FTP服务器

@echo off&@title FTP便携上传助手 By Lonelyer ^<hackkey@qq.com^>
pushd "%~dp0..\"
set "OLDPATH=C:\Program Files (x86)\SepanderSoft;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Program Files\dotnet\;H:\Go\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\bin"
set "PATH=%~dp0..\deps;%PATH%"
set "HOMEPATH=%~dp0..\"
set HOMEPATH=%HOMEPATH:~0,-1%
REM 兼容汉字文件名:使用了Mintty下面这行就可以不用,否则和.minttyrc冲突,起反作用
REM set LANG="zh_CN.GBK"

if "%1"=="" (echo\
echo 欢迎 %Username%!
echo FTP便携上传助手 By Lonelyer ^<hackkey@qq.com^>
echo\
echo ==============================
echo 使用说明:
echo 请把要上传的HTML文件直接拖拽到本文件上,即可进行上传...
echo\
echo 注意:1.文件完整路径(文件名和文件夹名称)中不要包含空格,否则会导致解析失败;
echo       2.文件名或文件夹名称可以包含中文汉字,不影响使用;
echo ==============================
echo\
ping -n 3 127.0.0.1>nul&color 0A
echo 本次不执行任何操作,按任意键退出本程序或直接关闭本窗口....
pause>nul&&exit
) 

REM 拉取最新密码
set "password="
set "passwordFile=rcfile/password.txt"
wget -O %passwordFile% http://source.xxx.com/nat/password.txt -o rcfile/wget.log

for /f %%n in (%passwordFile%) do (
   set "password=%%n"
)

REM echo =======================
REM echo %*
REM echo =======================
REM echo %*|sed -r "s#[\"]##g;s#[ ]#\\ #g;s#^\\##;s#\\$##"
REM >%~dp0fixfullpath.txt echo %*|sed -r "s#[\"]##g;s#[ ]#\\\ #g;s#^\\##;s#\\$##"
REM set "FixFullPath="
REM for /F "usebackq delims= tokens=*" %%t in (`type %~dp0fixfullpath.txt`) do (
REM set "FixFullPath=%%t"
REM )
REM echo FixFullPath %FixFullPath%
REM echo =======================

set "localFile="
set "FileName="
set "FilePath="
set "localFileExt="
set "FileDrive="
set "FileUnixSuffix="
for %%i in ("%*") do (
set localFile=%%~fi
set FileName=%%~nxi
set FilePath=%%~dpi
set localFileExt=%%~xi
set FileDrive=%%~di
set "FileUnixSuffix=%%~pnxi"
)

set FileDrive=%FileDrive::=%
set "FileUnixSuffix=%FileUnixSuffix:\=/%"
set "FullUnixPath=/cygdrive/%FileDrive%%FileUnixSuffix%"
REM 如果有空格,进行替换,测试无效
REM set "FullUnixPath=%FullUnixPath: =\ %"

REM echo %localFile%
REM echo %FileName%
REM echo %localFileExt%
REM echo %FileDrive%
REM echo 组合后路径:%FullUnixPath%

REM Push 到上传文件所在目录
REM pushd "%FilePath%"

if "%localFileExt%"==".htm" ( call :PutHTMLFile "%localFile%" html&goto endScript )
if "%localFileExt%"==".html" ( call :PutHTMLFile "%localFile%" html&goto endScript )
echo\
echo        你要上传的文件 %FileName% 不是HTML文件,是否确认上传本文件?
echo        输入 y 确认强制上传,或者直接关闭本窗口退出
echo\
set /p forcePut=

if "%forcePut%"=="y" ( call :PutHTMLFile "%localFile%"&goto endScript )
if "%forcePut%"=="Y" ( call :PutHTMLFile "%localFile%"&goto endScript )
exit


:PutHTMLFile
set PutFile=%1
@title 正在执行上传指令,请等待....
REM lftp -d -e "ls -al;!!dir;exit;" --rcfile ./rcfile/.lftprc -u ftp_web,12345678 ftp.xxx.com

echo\
echo    工作路径 %CD%
echo =^> 上传文件 %PutFile%
echo 上传过程中不要关闭窗口
echo\

REM set PutFile=%PutFile:\=\\%
REM echo %PutFile%

if "x%2"=="xhtml" (
sed -i "s#.5pt#1pt#g" %PutFile%
lftp -e "put "'"%FullUnixPath%"'" -o index.html;ls -al;exit;" --rcfile ./rcfile/.lftprc -u ftp_web,%password% ftp.xxx.com
) else (
lftp -e "put "'"%FullUnixPath%"'";ls -al;exit;" --rcfile ./rcfile/.lftprc -u ftp_web,%password% ftp.xxx.com
)
goto :eof


:endScript
echo\&echo 操作命令执行完毕....
REM echo  返回码:%ERRORLEVEL%
if "%ERRORLEVEL%"=="0" (
@title 上传成功!&color 0A
echo\
echo  目标文件("%FileName%")上传成功!
echo  你现在可以关闭本窗口或按任意键退出...
) else (
@title 操作失败,请截图本页面联系技术管理员反馈哦!&color 0C
echo\
echo   哦豁,操作失败
echo   本次任务失败,可能是由于用户名或密码不正确,或者服务器下线所致。
echo   请截图本页面联系管理员进行反馈!
echo   你现在可以关闭本窗口或按任意键退出...
)
pause>nul&&exit
goto :eof

pause

扫描二维码,在手机上阅读!

关于斐讯K2路由器 j.s9w.cc 劫持的问题。

用K2浏览器会发现很多时候浏览器访问网页的时候多了 js.s9w.cc的 js
网上说是斐讯K2在恶意注入,经测试后发现,只不过关掉“系统设置”---》“应用设置”里的“购物比价”功能即可。


扫描二维码,在手机上阅读!

CentOS6.x可用的rpmforge镜像源(清华大学镜像源)

https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el6/en/x86_64/rpmforge/RPMS/

Download the latest rpmforge-release rpm from
https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el6/en/x86_64/rpmforge/RPMS/
Install rpmforge-release rpm:
# rpm -Uvh rpmforge-release*rpm
Example:Then Install package rpm package:
# yum install xxxx

参考链接:
https://mirrors.tuna.tsinghua.edu.cn/help/repoforge/
https://centos.pkgs.org/6/repoforge-x86_64/aria2-1.14.1-1.el6.rf.x86_64.rpm.html
http://mirrorlist.repoforge.org/
http://mirror-status.repoforge.org/
http://ftp.tu-chemnitz.de/pub/linux/dag/redhat/el6/en/x86_64/rpmforge/RPMS/
https://mirrors.tuna.tsinghua.edu.cn/#


扫描二维码,在手机上阅读!

Bat自动获取管理员权限执行命令

在你的bat文件最顶部加入以下代码。

========================================

 @echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------    

==============================================

另外一种选择,安装Windows下sudo可执行文件,用sudo调用命令和脚本文件。
该程序由go语言开发

go get github.com/mattn/sudo
Then

sudo Example1Server.exe

https://github.com/mattn/sudo


扫描二维码,在手机上阅读!
Title - Artist
0:00