Home > OS >  Centos7 shell script USES the problem
Centos7 shell script USES the problem

Time:09-19

A, script, packaging emails a day, and uploaded to the server, after upload with the md5 check whether complete, such as incomplete to upload
, two problems are as follows: after the first upload files such as incomplete md5 can check and upload again, a second check md5 becomes normal, but the actual passed or not complete, manual for the remote md5 is that is not normal, but the script for the normal
Three, the code below
A=` date + % Y % m % d # ` date data
B=${a} _TXKJMAIL. SQL # SQL name
The IPX=192.168.96.159
IPX2=192.168.96.246
Export I=` date - d "2 day line" + "% Y % m % d" `
# check the Intranet server connectivity
Ping - 8 - w c 20 192.168.96.159
If the [[" $? "- eq" 0 "]]. Then
Echo ` date "+ % Y - m - % d % % T" ` "192.168.96.159 server, connect normal & gt;">/usr/local/logs/${a}. The log.
The else
Echo ` date "+ % Y - m - % d % % T" ` "192.168.96.159 server connection exception, script early termination" & gt;>/usr/local/logs/${a}. The log.
exit;
Fi

Ping - 8 - w c 20 192.168.96.246
If the [[" $? "- eq" 0 "]]. Then
Echo ` date "+ % Y - m - % d % % T" ` "192.168.96.246 server, connect normal & gt;">/usr/local/logs/${a}. The log.
The else
Echo ` date "+ % Y - m - % d % % T" ` "192.168.96.246 server connection exception, script early termination" & gt;>/usr/local/logs/${a}. The log.
exit;
Fi
# stop taking
Echo ` date "+ % Y - m - % d % % T" ` "is stop services" & gt;>/usr/local/logs/${a}. The log.
Service HTTPD stop
Systemctl stop postfix dovecot
# database backup
Echo ` date "+ % Y - m - % d % % T" ` "is the backup database & gt;">/usr/local/logs/${a}. The log.
Mysqldump uroot - p "NL0fcstsrJt7ApoX" -- the databases ewomail & gt;/ewomail/mail/$b
# packaged
Echo ` date "+ % Y - m - % d % % T" ` "are packaged files & gt;">/usr/local/logs/${a}. The log.
Tar - CZVF/usr/local/TXKJMAIL_ $a.t ar. Gz/ewomail/mail
# delete SQL backup statement
Echo ` date "+ % Y - m - % d % % T" ` "delete SQL statements" & gt;>/usr/local/logs/${a}. The log.
Rm - rf/ewomail/mail/$b

# up clothing
Systemctl start postfix dovecot
Service HTTPD start
Echo ` date "+ % Y - m - % d % % T" ` "start the mail services" & gt;>/usr/local/logs/${a}. The log.

# teletransmission packed file
# this procedure is a remote transmission using the rsync tool, use it is the premise of the rsync tool both PC prior to installation, additionally receives the file one party must be from close (or rsync will interact password will fail)
Echo ` date "+ % Y - m - % d % % T" ` "start remote file transfer & gt;">/usr/local/logs/${a}. The log.
Rsync - P - RSH=SSH/usr/local/TXKJMAIL_ $a.t ar. Gz [email protected]:/home/backup/bakmail TXKJ
Rsync - P - RSH=SSH/usr/local/TXKJMAIL_ $a.t ar. Gz [email protected]:/home/data_bak bakmail/TXKJ
Echo ` date "+ % Y - m - % d % % T" ` "file transfer completed & gt;">/usr/local/logs/${a}. The log.
Sleep 60 # wait for 60 seconds

# MD5 file comparison, and as the MD5 value is not the same, the retransmission
5 times
G=1 # loop counter
While [true] # write equivalent to an infinite loop, how to exit is controlled by the if
Do
Export c=` md5sum/usr/local/TXKJMAIL_ $a.t ar. Gz | awk '{print $1}' `
Export d=` SSH ${IPX} md5sum/home/backup/bakmail/TXKJ/TXKJMAIL_ $a.t ar. Gz | awk '{print $1}' `
Echo "159 local MD5: ${c}" & gt;>/usr/local/logs/${a}. The log.
Echo "159 distal MD5: ${d}" & gt;>/usr/local/logs/${a}. The log.

If the [[" $c "=" $d "]]. Then
Echo ` date "+ % Y - m - % d % % T" ` file MD5 check normal "on the" 159 server & gt;>/usr/local/logs/${a}. The log.
Break
Elif (" $g=5 "), Then
Echo - e "\ [033; 41 37 m ` date" + Y - m - % d % % % T "` 159 files on the server has tried to transfer ${g} time still is not successful, please deal with the problem manually \ [0 033 m" & gt; & gt;/usr/local/logs/${a}. The log;
Break
The else
Echo - e "\ [41, 033, 37 m ` date" + % Y - % m - % d % T "` 159 on the server file MD5 checksum abnormal retransmission first ${g} \ 033 [0 m & gt; & gt;/usr/local/logs/${a}. The log;
Rsync - P - RSH=SSH/usr/local/TXKJMAIL_ $a.t ar. Gz [email protected]:/home/backup/bakmail TXKJ
G=$(+ 1) ($g) # loop counter + 1
Fi
The done

H=1 # loop counter
While [true] # write equivalent to an infinite loop, how to exit is controlled by the if
Do
Export e=` md5sum/usr/local/TXKJMAIL_ $a.t ar. Gz | awk '{print $1}' `
Export f=` SSH ${IPX2} md5sum/home/data_bak/bakmail/TXKJ/TXKJMAIL_ $a.t ar. Gz | awk '{print $1}' `
Echo "246 local MD5: ${e}" & gt;>/usr/local/logs/${a}. The log.
Echo "246 distal MD5: ${} f" & gt;>/usr/local/logs/${a}. The log.

If the [[" $e "=" $f "]]. Then
Echo ` date "+ % Y - m - % d % % T" ` file MD5 check normal "on the" 246 server & gt;>/usr/local/logs/${a}. The log.
Break
Elif (" $h=5 "), Then
Echo - e "\ [033; 41 37 m ` date" + Y - m - % d % % % T "` 246 files on the server has tried to transfer ${h} time still is not successful, please deal with the problem manually \ [0 033 m" & gt; & gt;/usr/local/logs/${a}. The log;
Break
The else
Echo - e "\ [41, 033, 37 m ` date" + % Y - % m - % d % T "` 246 on the server file MD5 checksum abnormal retransmission first ${h} \ 033 [0 m & gt; & gt;/usr/local/logs/${a}. The log;
Rsync - P - RSH=SSH/usr/local/TXKJMAIL_ $a.t ar. Gz [email protected]:/home/data_bak bakmail/TXKJ
H=$(($h + 1)) # loop counter + 1
Fi
The done

# chmod -r 755/usr/local/
CD/usr/local/
/bin/find/usr/local/-name TXKJMAIL_ ${I}. The tar. Gz -type f - exec rm {} \;
Echo ` date "+ % Y - m - % d % % T" ` "deleting ${I}. Tar. Gz" & gt;>/usr/local/logs/${a}. The log.
Rsync - P - RSH=SSH/usr/local/logs/${a}. The log [email protected]:/home/backup/bakmail TXKJ/logs
Rsync - P - RSH=SSH/usr/local/logs/${a}. The log [email protected]:/home/data_bak bakmail/TXKJ/logs

Four, is after the operation screenshot below


5, this is in fact 246 will receive files on the server (normal is 1.5 g, actually just received 900 m)

CodePudding user response:

My own solved because rsync transmission failure process, will not immediately shut down because of failure, when the script after the normal package cover again
  • Related