Resolving git conflicts
If you do a rebase or a pull and it has a merge conflict do the following
1. Check for file that is having conflict
git status
2. Edit code that has conflict and git add
git add -a
3. Commit edit
git commit -am "Some message"
Git configs
Because I never seem to remember them
Global git ignore
echo ".DS_Store" >> ~/.gitignore git config --global core.excludesfile ~/.gitignore
My info
git config --global user.name "Your Name Comes Here" git config --global user.email you@yourdomain.example.com
Colorized outputs
git config --global color.branch auto git config --global color.diff auto git config --global color.interactive auto git config --global color.status auto
Puppet apt module
Testing out the code plugin
class apt {
file { '/etc/cron.daily/package.list':
owner => root,
group => root,
mode => 755,
source => "puppet:///files/etc/cron.daily/package.list"
}
file { "/etc/apt/sources.list":
owner => root,
group => root,
mode => 644,
source => $lsbdistcodename ? {
"squeeze" => "puppet:///files/etc/apt/sources.list.squeeze",
default => "puppet:///files/etc/apt/sources.list.squeeze"
}
}
file { '/etc/apt/apt.conf.d/10puppet' :
ensure => present,
owner => root,
group => root,
mode => 644,
source => "puppet:///files/etc/apt/apt.conf.d/10puppet"
}
file { '/usr/local/sbin/check-updates':
owner => root,
group => root,
mode => 755,
source => "puppet:///files/usr/local/bin/check-updates"
}
exec { 'apt-update':
command => "/usr/bin/apt-get -qq update",
logoutput => false,
refreshonly => true,
subscribe => [File["/etc/apt/sources.list"]]
}
}
sudo while in vim
Ever had a time when you opened a file in vim and edited a bunch of stuff without realizing that its read-only, well this solves you from exiting out of the file and reopening the file with sudo
:w !sudo tee %
Mail log fu
Ever had someone go "I need you to look through the logs and get me every email address this From address sent to". Well heres how (or at least the easiest way I can think of doing it)
grep "from=<foo@example.com>" /var/log/mail.log | awk '{if ($6 != "NOQUEUE:"){print $6}}' | sed 's/\://g' | while read SEARCH; do grep "${SEARCH}" /var/log/mail.log; done | grep "to=" | awk '{print $7}' | sed -r 's/^to=<(.+)>\,$/\1/g' | uniq
Here is a step by step walkthrough of whats going on
- We grep the from address out of the mail log
- Pipe the output to awk and get the 6th column which is the mail id, if the 6th column doesn't start with NOQUEUE print the output
- The output goes to sed which removes the ":" and
- Read the output and put it into a variable and from that variable go through the mail log again
- This time filter out the "to=" line from the mail log and print out the 7th column (which is the to address)
- Use sed to filter out the to=<> line to print out the actual email addresses
- Pass it through uniq to make sure there are no dupes
How to remove duplicate file
Taken from shell-fu
OUTF=rem-duplicates.sh;
echo "#! /bin/sh" > $OUTF;
find "$@" -type f -print0 |
xargs -0 -n1 md5sum |
sort --key=1,32 | uniq -w 32 -d --all-repeated=separate |
sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF;
chmod a+x $OUTF; ls -l $OUTF
Deleting special character files in UNIX
If you're an idiot like me and managed to create a file with special characters like --exclude=*.svn and need to remove it, here's how
rm ./'--exclude\=\*.svn'
Remember don't be an idiot like me
Checking expiration date for an SSL cert
Here is you how you check whether an SSL cert is valid and hasn't yet expired
1. Retrieve the certificate.
$ echo "" | openssl s_client -connect server:443 > certificate
2. Check the expiration date of the certificate.
$ openssl x509 -in certificate -noout -enddate
Or you can use ssl-cert-check or check-expire
Changing permissions for all directories in folder
Ever run into a situation where you have a mixture of both files and folders in a directory and you only need to change the permission of the folder? Naturally the first thing that comes to mind is to do something like this
find . -type d -print | xargs chmod 755
But what happens if your folders have spaces? Using find that way will not escape the spaces instead the solution to this is to use find but in a slightly different manner
find . -type d -print0 | xargs -0 chmod 755
The -print0 tells find to terminate with zero so that whitespaces are recognized and the same goes for xargs as well.
Taken from Shell-fu
This is taken from shell-fu.org still a pretty handy one liner though
aptitude search ~c | awk '{ print $2 }' | xargs aptitude -y purge
This will delete any packages that are not installed anymore which still has configuration files on the box