For work I use a Mac. Macs are totally broken in a lot of ways and when running utilities directly on the mac it has been the case more than once that I have to either suffer constant error messages or resort to trickery. Here's the trickery.
#============================================================
# ALIASES
#============================================================
alias vagrant="vagrant_suppress_gssapi_warnings"
alias puppet="puppet_suppress_iconv_warnings"
#============================================================
# FUNCTIONS
#============================================================
function vagrant_suppress_gssapi_warnings {
{
\vagrant "$@" 2>&1 >&3 | egrep -v 'Check your GSSAPI' >&2;
} 3>&1
}
function puppet_suppress_iconv_warnings {
{
\puppet "$@" 2>&1 >&3 | egrep -v 'iconv will be depr' >&2;
} 3>&1
}
Friday, October 19, 2012
Ruby Heredocs and whitespace
- raise(Puppet::Error, "this is a really really long line that causes total terminal line wrap. That's something I typically try to avoid whenever I can!")
+ raise(Puppet::Error, <<-EOL.gsub(/\s+/, " ").strip)
+ this is a really really long line that thanks to a
+ little bit of heredoc trickery can safely be multi
+ line, and the extra whitespace will be reduced down
+ to a single space. Pretty cool, eh!?
+ EOL
Saturday, October 6, 2012
Delete all blank lines and comments in Vim
Got a config file that doubles as a manual? Not any more:
:g/^$\|^#.*/d
:g/^$\|^#.*/d
Friday, May 18, 2012
Disks not in a zpool
Ever wish you had a simple one-liner to tell you which of your /dev/rdsk's weren't in a zpool? Well now you do...
diff <(zpool status | awk '/c.t.d./ {print $1}' | sort) <(ls /dev/rdsk/c?t?d? | cut -f4 -d/ | sort) | awk '/^>/ {print "free disk: " $2}'
Monday, April 9, 2012
Git Submodule Grepping
git grep doesn't work well when submodules are involved. Some specialized workflows and situations require superprojects though, and git grep is a heck of a lot faster than actually opening and reading all the files with grep. Problem: doesn't work across submodules. Solution: alias.
[alias]
[alias]
sgrep = "!f() { git grep \"$1\"; git submodule foreach \"git grep '$1'; true\" | grep -B 1 \"$1\"; }; f"
Monday, March 5, 2012
How much memory have you allocated?
for i in `virsh list | grep running | cut -d " " -f 3 | grep -v 9`; do virsh dumpxml $i | grep memory | sed s/\// | sed s/\<\\/memory\>// ; done | xargs | sed s/\ /+/g | bc
Monday, October 24, 2011
Of cats and redirection...
Let's say you want to cat a file and redirect the output to itself, something like:
cat file > file;
Or perhaps more usefully:
cat file | tail -n 100 > file;
You will end up with an empty file. This is likely because of how the shell handles inodes and redirection (just a guess). A quick and way to get around this is:
cat file | tail -n 100 | dd of=file;
And viola! file points at the correct inode.
Tuesday, August 30, 2011
Tar Directory Structure
16:37:31 <blkperl> hmm so how do you tell tar from 1998 to only tar the directory structure
16:38:29 <haus> port update tar?
16:38:42 <haus> or...yum update tar
16:38:43 <anakha> I don't think that's an option :)
16:41:22 <marut> mkdir tmp && cd tmp && ( cd .. && find . -type d ) | xargs mkdir -p && rmdir tmp && tar -cvf dirstructure.tar .
...rewind...
mkdir tmp && cd tmp && ( cd .. && find . -type d ) | xargs mkdir -p && rmdir tmp && tar -cvf dirstructure.tar .
...oh yeah.
Monday, August 22, 2011
pkginfo y u no read stdin
package_file="$(mkfifo tempfifo && (gunzip -c "packagename.pkg.gz" > tempfifo &) && pkginfo -d tempfifo | awk '/application / {print $2}')"
Wednesday, August 17, 2011
ZFS chmod -R and what not to do
Suppose you need to recursively apply a ZFS ACE to a directory structure. This is what you should not start by doing:
find . -type d -exec chmod -R A+group:videocat:r-x---a-R-c--s:-d----:allow {} \;
The problem is the -R. Guess what that does. :)
Chant fix!
for each in `find . -type d`; do while ls -dV $each | grep videocat > /dev/null; do chmod A0- $each; done; done;
Thursday, June 30, 2011
python shell
ipython has some bugs in it, but readline and tabcompletion are not-exactly-modern marvels
so, add this to your .bashrc
alias pysh='python -ic "import readline, rlcompleter;readline.parse_and_bind('\''tab:complete'\'')"'
credit for this one goes to MostAwesomeDude
so, add this to your .bashrc
alias pysh='python -ic "import readline, rlcompleter;readline.parse_and_bind('\''tab:complete'\'')"'
credit for this one goes to MostAwesomeDude
Thursday, June 23, 2011
Find 3.2
While find can be used to recursive perform an operation on files with the -exec flag, doing so can be costly. In the case of recursive permissions, you could change
To
chmod -R a+rX .
This recursively adds the read bit to all files, and if the execute bit is set for user, group, or other on the file, it is applied for all else. If you're updating 10000+ files, this will run much faster. (And it's easier to type.)
find . -type f -exec chmod 644 {} + -o -type d -exec chmod 755 {} +
To
chmod -R a+rX .
This recursively adds the read bit to all files, and if the execute bit is set for user, group, or other on the file, it is applied for all else. If you're updating 10000+ files, this will run much faster. (And it's easier to type.)
Wednesday, June 22, 2011
ldapsearchin
ldapsearch -LLL -x -h ldap.schoolname.edu -D uid=me,ou=People,dc=shcoolname,dc=edu -b ou=Group,dc=schoolname,dc=edu gidNumber=* gidNumber |grep gidNumber | cut -f2 -d" " | sort -g
Monday, June 20, 2011
Find 3.1
Here are the last two finds combined into a one-liner:
find . -type f -exec chmod 644 {} + -o -type d -exec chmod 755 {} +
The '+' can replace the escaped ';' to tell the find exec to collect all the files first, and then execute (think xargs). And the '-o' will be short-circuited, so it will only test for a type of 'd' if the type is not 'f'.
find 3
First, find all directories starting in the current directory and recursing deeper, and chmod them all to 755.
Then, find all files starting in the current directory and recursing deeper, and chmod them all to 644.
Sweet.
find . -type d -exec chmod 755 {} \;Then, find all files starting in the current directory and recursing deeper, and chmod them all to 644.
find . -type f -exec chmod 644 {} \;Sweet.
Saturday, June 18, 2011
Friday, June 17, 2011
find
the first in a series on find
find . | xargs grep foobar
Innagural spell
Using cut to chop things
Will print out the first part up to the '-' of every line in the file /etc/dfs/sharetab
cut -f1 -d"-" /etc/dfs/sharetab
Will print out the first part up to the '-' of every line in the file /etc/dfs/sharetab
Subscribe to:
Posts (Atom)