using ctrl+r to replay a command from history đ
with tab completion
Figuring things out, to get it done!
using ctrl+r to replay a command from history đ
with tab completion
I have a little cron job that syncs two svn repos. It runs every ten minutes. For some reason it stopped working so I killed the job. Now when I try to manually run the job, I get:
Failed to get lock on destination repos, currently held by...
Great, the sync is broken!
Here is how to clear it up. Use the following command to remove the lock:
svn propdel --revprop -r0 svn:sync-lock file:///path/to/the/repository
This is the sync script:
#!/bin/sh svnsync synchronize file:///path/to/the/repository --username svnuser --password svnpassword
First, we need to make sure the DESTSERVER has the ability to use key authentication enabled. Find your sshd configuration file (usually â/etc/ssh/sshd_configâ) and enable the following options if they are not already set.
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys
If you edit the file be sure to restart sshd afterwards.
# /etc/init.d/sshd restart
Next, on the SOURCESERVER we will create the public / private key pair to be used for authentication with the following command.
# ssh-keygen -t rsa
This should create 2 files, a public key file and a private key file. The public key file (usually [homedir]/.ssh/id_rsa.pub) we will upload to the DESTSERVER. The private key file (usually [homedir]/.ssh/id_rsa) we will keep on the SOURCESERVER.
Now we will plant the public key we created on to the DESTSERVER. Choose the user account which you will use to connect to on DESTSERVER, weâll call this user âdestuserâ for now.
In that accountâs home directory, create a â.sshâ subdirectory, and in that directory create a new text file called âauthorized_keysâ. If it already exists, great, use the existing file. Open the âauthorized_keysâ file and paste in the contents of the public key you created in the previous step (id_rsa.pub). It should look something like the following
ssh-rsa <lots and lots of charactersâŚ> sourceuser@SOURCESERVER
Save the file and change the permissions to 600 for the file and 700 for the â.sshâ directory.
Now to test that the keys are working. From the SOURCESERVER try logging in as normal using ssh to the DESTSERVER.
# ssh destuser@DESTSERVER
If all is working you should not be prompted for a password but instead connected directly to a shell on the DESTSERVER.
Now for the rsync script.
#!/bin/sh SOURCEPATH=â/var/svn/workingcopies/beta.app.jp/â DESTPATH=â/var/www/lamp_root/wwwapps/app.jpâ DESTUSER=âupdaterâ LOGFILE=â/var/log/rsync_beta.logâ echo $â\n\nâ >> $LOGFILE for SERVER in web01 web02 do rsync -av ârsh=ssh $SOURCEPATH $DESTUSER@$SERVER:$DESTPATH 2>&1 >> $LOGFILE echo âCompleted at: `/bin/date`â >> $LOGFILE done
This is optional. I assume web updates will be done manually.
Assuming everything has worked so far all thatâs left is to setup a cron job to run the script automatically at a predefined interval.
Use the âcrontabâ command to create a new cron job.
>sudo crontab -e -u updater
This will open an editor where you can schedule the job.
Enter the following to have the script run once every hour
0 * * * * /var/scripts/rsync_betajp.sh
If your sites are in multiple geographical locations, this script will show where a site currently is being served from. It colors the output based on location.
#!/bin/bash
# where_are_you.sh
#do a dig against the company name servers and spit out the current IP of the sites.
array=( www.site.com www.site2.com www.site3.com www.site99.com )
for i in “${array[@]}”
do
dig @ns.server.company $i a | grep -v ‘;’ |grep $i | awk ‘{ if ( substr($5, 1, 8) == “x.x.x” ) printf “%-30s %s\n”, “\033[1;32;40m”$5,$1; else printf “%-30s %s\n”, “\033[1;34;40m”$5,$1 }’
done | sort -n
tput sgr0
This is a work in progress…
List Client IP and Count Hits
awk -F'[ “]+’ ‘$7 == “/” { ipcount[$1]++ } END { for (i in ipcount) { printf “%15s – %d\n”, i, ipcount[i] } }’ access.log
List Client IP and RDNS
cat access.log | awk ‘{print $1}’ | logresolve