Saturday, July 30, 2016

Scripts

1) Create svnupload.sh  -------local svn script

vim /usr/local/subversion/harry/svnupload.sh

#/bin/sh!
home_dir=/usr/local/subversion/harry
#> /usr/local/subversion/harry/test.txt
svnlook changed /usr/local/subversion/harry >> /usr/local/subversion/harry/test.txt
cat  /usr/local/subversion/harry/test.txt| sed 's/^[A-Z]//g'| sed 's/^  //g' >> /usr/local/subversion/harry/upload.txt
for i in `cat /usr/local/subversion/harry/upload.txt`;do svn export --username 'harry' --password 'harry@123' --no-auth-cache  http://localhost:82/harry/$i /mnt/httpdocs/harry/$i --force;done
for i in `cat /usr/local/subversion/harry/upload.txt`;do chown -R apache:apache /mnt/httpdocs/harry/$i ;done
for i in `cat /usr/local/subversion/harry/upload.txt`;do chmod -R 775 /mnt/httpdocs/harry/$i ;done
> /usr/local/subversion/harry/test.txt
> /usr/local/subversion/harry/upload.txt

Chech localhost port
######################## THE END #####################

2) Jenkins Script

#!/bin/bash
################## setting function Document Root##########################

t1="project name"
url="http://mastersvn.hungamatech.com/svn/"$t1""
htdocs="/usr/local/apache/htdocs"

################ setting functions for backup Dir #################

DATE_TIME=`date +%Y_%m_%d_%H_%M_%S`
backdir=/tmp/"$t1"_$DATE_TIME
/bin/mkdir $backdir
cd $backdir

#################### setting authentication function for svn user #######################
uname=svn
passwd="svn123"

################## setting function for tmpfile ##########
tmpfile=/tmp/svnchanged_tmpfile.txt
tarfile=/tmp/tarfiles_"$t1".txt

###############  calling Head Revision from mastersvn URL #####################

[ -z $1 ] && Revision=HEAD || Revision=$1
svn log --non-interactive --username=$uname --password="$passwd" --verbose  -r $Revision $url |grep -E 'M /|A /|D /|R /'| awk {'print $2'}|sed -e 's/^\///' > $tmpfile

###################### taking backup of previous revision  ################

for i in `cat $tmpfile`;do /bin/cp $htdocs/$i $backdir/$i ;done
/bin/tar zcvf /tmp/$DATE_TIME.tar.gz .
/bin/rm -rf $backdir

######## exporting Head Revision from mastersvn URL  to document root ##############

for i in `cat $tmpfile`;do svn export --username=$uname --password="$passwd" --no-auth-cache $url/$i $htdocs/$i --force;done
for i in `cat $tmpfile`;do chown -R apache:apache $htdocs/$i ;done

####################### Exporting files to Remote servers (192.168.10.11) ########
scp $tmpfile root@192.168.10.XX:/tmp/temp_svncheck/
ssh root@192.168.10.XX /root/scripts/billing_svnexport.sh

##################### truncating tmpfile ######################
> $tmpfile

########################### THE END #######################################

2 ) for SVN

#/bin/sh!
home_dir=/tmp/temp_svncheck/
tmpfile=/tmp/temp_svncheck/svnchanged_tmpfile.txt

for i in `cat $tmpfile`;do svn export --username="svn" --password="svn123" --no-auth-cache http://mastersvn.hungamatech.com/svn/test/$i /usr/local/apache/htdocs/$i --force;done
for i in `cat $tmpfile`;do chown -R apache:apache /usr/local/apache/htdocs/$i ;done
for i in `cat $tmpfile`;do chmod -R 775 /usr/local/apache/htdocs/$i ;done
> $tmpfile

########################### THE END #######################################

!#/bin/sh
$1=access_log_4.txt
for i in {1..30}
do
   less access_log_4.txt | grep "04:$i" > accesslog_4_$i.txt
done
########################### THE END #######################################

#!bin/bash

curDay=`date +"%Y%m%d"`
#echo "$curDay"
find /opt/apache-tomcat-8.0.20/logs/ -mtime -7 -print | grep 'localhost_access_log' | sort | while read LINE; do echo "$LINE : "`bzgrep 'create' $LINE | wc -l`; done > /opt/apache-tomcat-8.0.20/logs/data/unique_user_count_"$curDay".log

########################### THE END #######################################

#!bin/bash

var=`ps aux|grep 'apache-tomcat-8.0.20'|wc -l`

current=`date +"%Y-%m-%d %T"`
if [ $var -lt 2 ]; then
        echo $current" --> tomcat is not runing."
        `sh /opt/apache-tomcat-8.0.20/bin/startup.sh`
        echo $current" --> tomcat was stop bcz of some reason, but now started."
else
        echo $current" --> tomcat is runing"
fi

########################### THE END #######################################

I have the following backup script that packs my current folders contents to an external hard disk (in my company we have enough hard disks so there is no really need to do incremental backups)
Code:
echo '----- Backup Started '`date` >>/root/backup/backuperrors.txt
tar -zcvf /media/a9f299d7-fcbc28b3f3c0/user-host`date '+%d-%B-%Y'`.tar.gz /etc /root /home 2>> /root/backup/backuperrors.txt

########################### THE END #######################################

Script for RDS (More 10m runing QUERY KILL)

[root@localhost_scripts]# cat newRDS_BSC.sh
HOST='mtp2newreadreplicanewttp.cgckm3nudvpd.us-east-1.rds.amazonaws.com'
USER='user1'
PASS='password123'
TIME='600'

for i in `mysql -h $HOST  -u $USER -p$PASS -A --skip-column-names -e "SELECT ID, USER, TIME FROM information_schema.PROCESSLIST WHERE USER='$USER' AND TIME > $TIME;" | grep "$USER" | awk '{print $1}'` ;
        do
        mysql -h $HOST -u $USER -p$PASS -A --skip-column-names -e "KILL QUERY $i;" ;
        echo "KILL QUERY $i;"
done

########################### THE END #######################################

Script for RDS (Kill all ruing Query of user1 user)

[root@localhost_scripts]# cat newRDS_BSC1.sh
for i in `mysql -h mtp2newreadreplicanewttp.cgckm3nudvpd.us-east-1.rds.amazonaws.com  -u'user1' -p'password123' -A --skip-column-names -e"SHOW PROCESSLIST" | grep "user1" | awk '{print $1}'` ; do mysql -h mtp2newreadreplicanewttp.cgckm3nudvpd.us-east-1.rds.amazonaws.com -u 'user1' -p'password123' -A --skip-column-names -e"KILL QUERY $i" ; done

########################### THE END #######################################

Kill test user query RDS

[root@RDS ~]# for i in `mysql -uroot -padmin123 -A --skip-column-names -e"SHOW PROCESSLIST" | grep "test" | awk '{print $1}'` ; do mysql -uroot -padmin123 -A --skip-column-names -e"kill $i;" ; done

########################### THE END #######################################
Delete   30 days old logs

#!/bin/bas
#take output in a file
find  /solrd/apache-tomcat-7.0.64/logs/ -type f -mtime +30 > /tmp/solrd_apache-7.064

#delete 30 days old files
find  /solrd/apache-tomcat-7.0.64/logs/ -type f -mtime +30 -exec rm -f {} +

#take output in a file

find /tomcat2001/apache-tomcat-7.0.64/logs/ -type f -mtime +30 > /tmp/tomcat2001_tomcat-7.064
#delete 30 days old files

find /tomcat2001/apache-tomcat-7.0.64/logs/ -type f -mtime +30 -exec rm -f {} +

########################### THE END #######################################
Zip log before 2day
#!/bin/sh
find /mnt/logs/apilogs -type f -name "*.txt" -mtime +2 > /tmp/apilogs.txt
for i in `cat /tmp/apilogs.txt`;
do bzip2 $i;
done########################### THE END #######################################

#!/bin/sh

find /mnt/logs/httplogs -type f -name "*.log" -mtime +2 > /tmp/httplogs.txt

for i in `cat /tmp/httplogs.txt`;

do bzip2 $i;

done

########################### THE END #######################################
[root@intl-live htdocs]# cat svnupload.sh
#/bin/sh!
home_dir=/usr/local/subversion/htdocs147/
svnlook changed /usr/local/subversion/htdocs >> /usr/local/subversion/htdocs/test.txt
cat /usr/local/subversion/htdocs147/test.txt| sed 's/^[A-Z]//g'| sed 's/^ //g' >> /usr/local/subversion/htdocs147/upload.txt
sshpass -p 'br!$b@nexxx' scp /usr/local/subversion/htdocs/upload.txt root@192.168.10.x:/usr/local/subversion/svnscript/upload.txt
> /usr/local/subversion/htdocs147/test.txt
> /usr/local/subversion/htdocs147/upload.txt
sshpass -p 'br!$b@ne134' ssh root@192.168.10.x 'sh -x /usr/local/subversion/svnscript/svnupload.sh'
########################### THE END #######################################
#!/bin/bash
SSH='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
$SSH svn@10.171.x.x "sudo /bin/chown -R svn:svn /mnt/httpdocs/project_name"
rsync -avzOp /var/lib/jenkins/jobs/hisense/workspace/ -e "$SSH" svn@10.171.x.x:/mnt/httpdocs/project_name  --exclude '.svn'
$SSH svn@10.171.x.x "sudo /bin/chown -R apache:apache /mnt/httpdocs/project_name"

$SSH svn@10.237.x.x "sudo /bin/chown -R svn:svn /mnt/httpdocs/project_name"
rsync -avzOp /var/lib/jenkins/jobs/project_name/workspace/ -e "$SSH" svn@10.237.x.x:/mnt/httpdocs/project_name --exclude '.svn'
$SSH svn@10.237.x.x "sudo /bin/chown -R apache:apache /mnt/httpdocs/project_name"

No comments:

Post a Comment