This commit is contained in:
condor
2026-07-24 18:54:53 +08:00
parent 43c2a411b9
commit 679e0b4184
128 changed files with 13855 additions and 1 deletions
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env python
# Author: yeho <lj2007331 AT gmail.com>
# Blog: http://linuxeye.com
import socket,sys
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sk.settimeout(1)
try:
sk.connect((sys.argv[1],int(sys.argv[2])))
print ('ok')
except Exception:
print ('no')
sk.close()
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://linuxeye.com
#
# Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://oneinstack.com
# https://github.com/oneinstack/oneinstack
. ../config/options.conf
. ../lib/check_dir.sh
DBname=$1
LogFile=${backup_dir}/db.log
DumpFile=${backup_dir}/DB_${DBname}_$(date +%Y%m%d_%H%M%S).sql
NewFile=${backup_dir}/DB_${DBname}_$(date +%Y%m%d_%H%M%S).tgz
OldFile=${backup_dir}/DB_${DBname}_$(date +%Y%m%d --date="${expired_days} days ago")*.tgz
[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
DB_tmp=`${db_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "show databases\G" | grep ${DBname}`
[ -z "${DB_tmp}" ] && { echo "[${DBname}] not exist" >> ${LogFile} ; exit 1 ; }
if [ -n "`ls ${OldFile} 2>/dev/null`" ]; then
rm -f ${OldFile}
echo "[${OldFile}] Delete Old File Success" >> ${LogFile}
else
echo "[${OldFile}] Delete Old Backup File" >> ${LogFile}
fi
if [ -e "${NewFile}" ]; then
echo "[${NewFile}] The Backup File is exists, Can't Backup" >> ${LogFile}
else
${db_install_dir}/bin/mysqldump -uroot -p${dbrootpwd} --databases ${DBname} > ${DumpFile}
pushd ${backup_dir} > /dev/null
tar czf ${NewFile} ${DumpFile##*/} >> ${LogFile} 2>&1
echo "[${NewFile}] Backup success ">> ${LogFile}
rm -f ${DumpFile}
popd > /dev/null
fi
+168
View File
@@ -0,0 +1,168 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# Blog: http://linuxeye.com
###################### proc defination ########################
# ignore rule
ignore_init() {
# ignore password
array_ignore_pwd_length=0
if [ -f ./ignore_pwd ]; then
while read IGNORE_PWD
do
array_ignore_pwd[$array_ignore_pwd_length]=$IGNORE_PWD
let array_ignore_pwd_length=$array_ignore_pwd_length+1
done < ./ignore_pwd
fi
# ignore ip address
array_ignore_ip_length=0
if [ -f ./ignore_ip ]; then
while read IGNORE_IP
do
array_ignore_ip[$array_ignore_ip_length]=$IGNORE_IP
let array_ignore_ip_length=$array_ignore_ip_length+1
done < ./ignore_ip
fi
}
show_ver() {
echo "version: 1.0"
echo "updated date: 2014-06-08"
}
show_usage() {
echo -e "`printf %-16s "Usage: $0"` [-h|--help]"
echo -e "`printf %-16s ` [-v|-V|--version]"
echo -e "`printf %-16s ` [-l|--iplist ... ]"
echo -e "`printf %-16s ` [-c|--config ... ]"
echo -e "`printf %-16s ` [-t|--sshtimeout ... ]"
echo -e "`printf %-16s ` [-T|--fttimeout ... ]"
echo -e "`printf %-16s ` [-L|--bwlimit ... ]"
echo -e "`printf %-16s ` [-n|--ignore]"
}
IPLIST="iplist.txt"
CONFIG_FILE="config.txt"
IGNRFLAG="noignr"
SSHTIMEOUT=100
SCPTIMEOUT=2000
BWLIMIT=1024000
[ ! -e 'logs' ] && mkdir logs
TEMP=`getopt -o hvVl:c:t:T:L:n --long help,version,iplist:,config:,sshtimeout:,fttimeout:,bwlimit:,log:,ignore -- "$@" 2>/dev/null`
[ $? != 0 ] && echo -e "\033[31mERROR: unknown argument! \033[0m\n" && show_usage && exit 1
eval set -- "$TEMP"
while :; do
[ -z "$1" ] && break;
case "$1" in
-h|--help)
show_usage; exit 0
;;
-v|-V|--version)
show_ver; exit 0
;;
-l|--iplist)
IPLIST=$2; shift 2
;;
-c|--config)
CONFIG_FILE=$2; shift 2
;;
-t|--sshtimeout)
SSHTIMEOUT=$2; shift 2
;;
-T|--fttimeout)
SCPTIMEOUT=$2; shift 2
;;
-L|--bwlimit)
BWLIMIT=$2; shift 2
;;
--log)
LOG_FILE=$2; shift 2
;;
-n|--ignore)
IGNRFLAG="ignr"; shift
;;
--)
shift
;;
*)
echo -e "\033[31mERROR: unknown argument! \033[0m\n" && show_usage && exit 1
;;
esac
done
################ main #######################
BEGINDATETIME=`date "+%F %T"`
[ ! -f $IPLIST ] && echo -e "\033[31mERROR: iplist \"$IPLIST\" not exists, please check! \033[0m\n" && exit 1
[ ! -f $CONFIG_FILE ] && echo -e "\033[31mERROR: config \"$CONFIG_FILE\" not exists, please check! \033[0m\n" && exit 1
IP_count=$(egrep -v '^#|^$' $IPLIST|wc -l)
IP_init=1
while [[ $IP_init -le $IP_count ]]
do
egrep -v '^#|^$' $IPLIST | sed -n "$IP_init,$(expr $IP_init + 50)p" > $IPLIST.tmp
IPSEQ=0
while read IP PORT USER PASSWD PASSWD_2ND PASSWD_3RD PASSWD_4TH OTHERS
# while read Line
do
#[ -z "`echo $IP | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|CNS'`" ] && continue
if [ "`python ./ckssh.py $IP $PORT`" == 'no' ]; then
[ ! -e ipnologin.txt ] && > ipnologin.txt
[ -z "`grep $IP ipnologin.txt | grep $(date +%F)`" ] && echo "`date +%F_%H%M` $IP" >> ipnologin.txt
continue
fi
#[ -e "~/.ssh/known_hosts" ] && grep $IP ~/.ssh/known_hosts | sed -i "/$IP/d" ~/.ssh/known_hosts
let IPSEQ=$IPSEQ+1
if [ $IGNRFLAG == "ignr" ]; then
ignore_init
ignored_flag=0
i=0
while [ $i -lt $array_ignore_pwd_length ]
do
[ ${PASSWD}x == ${array_ignore_pwd[$i]}x ] && ignored_flag=1 && break
let i=$i+1
done
[ $ignored_flag -eq 1 ] && continue
j=0
while [ $j -lt $array_ignore_ip_length ]
do
[ ${IP}x == ${array_ignore_ip[$j]}x ] && ignored_flag=1 && break
let j=$j+1
done
[ $ignored_flag -eq 1 ] && continue
fi
PASSWD_USE=$PASSWD
IPcode=$(echo "ibase=16;$(echo "$IP" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
Portcode=$(echo "ibase=16;$(echo "$PORT" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
#USER=$USER
PWcode=$(echo "ibase=16;$(echo "$PASSWD_USE" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
Othercode=$(echo "ibase=16;$(echo "$OTHERS" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
#echo $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode
./thread.sh $IPcode $Portcode $USER $PWcode $CONFIG_FILE $SSHTIMEOUT $SCPTIMEOUT $BWLIMIT $Othercode | tee logs/$IP.log &
done < $IPLIST.tmp
sleep 3
IP_init=$(expr $IP_init + 50)
done
ENDDATETIME=`date "+%F %T"`
echo "$BEGINDATETIME -- $ENDDATETIME"
echo "$0 $* --excutes over!"
exit 0
+158
View File
@@ -0,0 +1,158 @@
#!/usr/bin/expect --
proc Usage_Exit {self} {
puts ""
puts "Usage: $self ip user passwd port sourcefile destdir direction bwlimit timeout"
puts ""
puts " sourcefile: a file or directory to be transferred"
puts " 需要拷贝目录时目录名后不要带 /, 否则会拷贝该目录下的所有文件"
puts " destdir: the location that the sourcefile to be put into"
puts " direction: pull or push"
puts " pull: remote -> local"
puts " push: local -> remote"
puts " bwlimit: bandwidth limit, kbit/s, 0 means no limit"
puts " timeout: timeout of expect, s, -1 means no timeout"
puts ""
exit 1
}
if { [llength $argv] < 9 } {
Usage_Exit $argv0
}
set ipcode [lindex $argv 0]
set ip [exec dc -e $ipcode]
set user [lindex $argv 1]
set passwduncode [lindex $argv 2]
set passwd [exec dc -e $passwduncode]
set portcode [lindex $argv 3]
set port [exec dc -e $portcode]
set sourcefile [lindex $argv 4]
set destdir [lindex $argv 5]
set direction [lindex $argv 6]
set bwlimit [lindex $argv 7]
set timeoutflag [lindex $argv 8]
set yesnoflag 0
set timeout $timeoutflag
for {} {1} {} {
# for is only used to retry when "Interrupted system call" occured
if { $direction == "pull" } {
if { $bwlimit > 0 } {
spawn rsync -crazP --delete --bwlimit=$bwlimit -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $ip:$sourcefile $destdir
} elseif { $bwlimit == 0 } {
spawn rsync -crazP --delete -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $ip:$sourcefile $destdir
} else {
Usage_Exit $argv0
}
} elseif { $direction == "push" } {
if { $bwlimit > 0 } {
spawn rsync -crazP --delete --bwlimit=$bwlimit -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $sourcefile $ip:$destdir
} elseif { $bwlimit == 0 } {
spawn rsync -crazP --delete -e "/usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port" $sourcefile $ip:$destdir
} else {
Usage_Exit $argv0
}
} else {
Usage_Exit $argv0
}
expect {
"assword:" {
send "$passwd\r"
break;
}
"yes/no" {
set yesnoflag 1
send "yes\r"
break;
}
"FATAL" {
puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
exit 1
}
timeout {
puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
exit 1
}
"No route to host" {
puts "\nCONNECTERROR: $ip No route to host!!!\n"
exit 1
}
"Connection Refused" {
puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
exit 1
}
"Connection refused" {
puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
exit 1
}
"Host key verification failed" {
puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
exit 1
}
"Illegal host key" {
puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
exit 1
}
"Connection Timed Out" {
puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
exit 1
}
"Interrupted system call" {
puts "\n$ip Interrupted system call!!!\n"
}
}
}
if { $yesnoflag == 1 } {
expect {
"assword:" {
send "$passwd\r"
}
"yes/no)?" {
set yesnoflag 2
send "yes\r"
}
}
}
if { $yesnoflag == 2 } {
expect {
"assword:" {
send "$passwd\r"
}
}
}
expect {
"assword:" {
send "$passwd\r"
puts "\nPASSWORDERROR: $ip Password error!!!\n"
exit 1
}
eof {
puts "OK_SCP: $ip\n"
exit 0;
}
}
+129
View File
@@ -0,0 +1,129 @@
#!/usr/bin/expect --
if { [llength $argv] < 4 } {
puts "Usage: $argv0 ip user passwd port commands timeout"
exit 1
}
match_max 600000
set ipcode [lindex $argv 0]
set ip [exec dc -e $ipcode]
set user [lindex $argv 1]
set passwdcode [lindex $argv 2]
set passwd [exec dc -e $passwdcode]
set portcode [lindex $argv 3]
set port [exec dc -e $portcode]
set commands [lindex $argv 4]
set timeoutflag [lindex $argv 5]
set yesnoflag 0
set timeout $timeoutflag
for {} {1} {} {
# for is only used to retry when "Interrupted system call" occured
spawn /usr/bin/ssh -o GSSAPIAuthentication=no -q -l$user -p$port $ip
expect {
"assword:" {
send "$passwd\r"
break;
}
"yes/no)?" {
set yesnoflag 1
send "yes\r"
break;
}
"FATAL" {
puts "\nCONNECTERROR: $ip occur FATAL ERROR!!!\n"
exit 1
}
timeout {
puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
exit 1
}
"No route to host" {
puts "\nCONNECTERROR: $ip No route to host!!!\n"
exit 1
}
"Connection Refused" {
puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
exit 1
}
"Connection refused" {
puts "\nCONNECTERROR: $ip Connection Refused!!!\n"
exit 1
}
"Host key verification failed" {
puts "\nCONNECTERROR: $ip Host key verification failed!!!\n"
exit 1
}
"Illegal host key" {
puts "\nCONNECTERROR: $ip Illegal host key!!!\n"
exit 1
}
"Connection Timed Out" {
puts "\nCONNECTERROR: $ip Logon timeout!!!\n"
exit 1
}
"Interrupted system call" {
puts "\n$ip Interrupted system call!!!\n"
}
}
}
if { $yesnoflag == 1 } {
expect {
"assword:" {
send "$passwd\r"
}
"yes/no" {
set yesnoflag 2
send "yes\r"
}
}
}
if { $yesnoflag == 2 } {
expect {
"assword:" {
send "$passwd\r"
}
}
}
expect {
"@" {send "$commands \r"}
"assword:" {
send "$passwd\r"
puts "\nPASSWORDERROR: $ip Password error!!!\n"
exit 1
}
}
expect {
"@" {send "sleep 1\r"}
}
expect {
"@" {send "exit\r"}
}
expect eof {
puts "OK_SSH: $ip\n"
exit 0;
}
+46
View File
@@ -0,0 +1,46 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# Blog: http://linuxeye.com
# Default Parameters
myIFS=":::"
IP=$1P
PORT=$2P
USER=$3
PASSWD=$4P
CONFIG_FILE=$5
SSHTIMEOUT=$6
SCPTIMEOUT=$7
BWLIMIT=$8
while read eachline
do
[ -z "`echo $eachline | grep -E '^com|^file'`" ] && continue
myKEYWORD=`echo $eachline | awk -F"$myIFS" '{ print $1 }'`
myCONFIGLINE=`echo $eachline | awk -F"$myIFS" '{ print $2 }'`
if [ "$myKEYWORD"x == "file"x ]; then
SOURCEFILE=`echo $myCONFIGLINE | awk '{ print $1 }'`
DESTDIR=`echo $myCONFIGLINE | awk '{ print $2 }'`
DIRECTION=`echo $myCONFIGLINE | awk '{ print $3 }'`
./mscp.exp $IP $USER $PASSWD $PORT $SOURCEFILE $DESTDIR $DIRECTION $BWLIMIT $SCPTIMEOUT
[ $? -ne 0 ] && echo -e "\033[31mSCP Try Out All Password Failed\033[0m\n"
elif [ "$myKEYWORD"x == "com"x ]; then
./mssh.exp $IP $USER $PASSWD $PORT "${myCONFIGLINE}" $SSHTIMEOUT
[ $? -ne 0 ] && echo -e "\033[31mSSH Try Out All Password Failed\033[0m\n"
else
echo "ERROR: configuration wrong! [$eachline] "
echo " where KEYWORD should not be [$myKEYWORD], but 'com' or 'file'"
echo " if you dont want to run it, you can comment it with '#'"
echo ""
exit
fi
done < $CONFIG_FILE
exit 0
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://linuxeye.com
#
# Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://oneinstack.com
# https://github.com/oneinstack/oneinstack
. ../config/options.conf
WebSite=$1
LogFile=${backup_dir}/web.log
NewFile=${backup_dir}/Web_${WebSite}_$(date +%Y%m%d_%H).tgz
OldFile=${backup_dir}/Web_${WebSite}_$(date +%Y%m%d --date="${expired_days} days ago")*.tgz
[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
[ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist" >> ${LogFile} ; exit 1 ; }
if [ `du -sm "${wwwroot_dir}/${WebSite}" | awk '{print $1}'` -lt 1024 ]; then
if [ -n "`ls ${OldFile} 2>/dev/null`" ]; then
rm -f ${OldFile}
echo "[${OldFile}] Delete Old File Success" >> ${LogFile}
else
echo "[${OldFile}] Delete Old Backup File" >> ${LogFile}
fi
if [ -e "${NewFile}" ]; then
echo "[${NewFile}] The Backup File is exists, Can't Backup" >> ${LogFile}
else
pushd ${wwwroot_dir} > /dev/null
tar czf ${NewFile} ./${WebSite} >> ${LogFile} 2>&1
echo "[${NewFile}] Backup success ">> ${LogFile}
popd > /dev/null
fi
else
rsync -crazP --delete ${wwwroot_dir}/${WebSite} ${backup_dir}
fi