/usr/ben
Tuesday, July 5, 2011
Astronaut Icecream
hxxp://www.mediafire.com/?zxvvp8nf02v3mmc
md5: 6061318096ddf6ef9d43a817382ee3cc
The music contained within this mix does not belong to me and this mix is for evaluation purposes only. Please support your favorite artists by purchasing their music. Any take down requests will be honored promptly.
Tuesday, June 28, 2011
Passing environmental variables through sudo in Perl
In the process of writing a set of backup scripts in Perl, I ran into a slight caveat with my overall design - after `rsync`'ing the files to be backed up to it's working directory, the backup user does not have the permissions to be able to delete the files before doing a clean backup. To solve this, I created a subscript that when called, checks the parent process for authorization and configuration, and then chown's the working directory to the calling user, in this case backup.
Now comes the question of how to determine the calling user. `sudo -E` allows us to pass environmental variables through sudo. Here is an example:
To work around this issue, we can do as follows:
You can even `chmod` subscript.pl to 750 and then just add an entry to your /etc/sudoers file like this:
Now comes the question of how to determine the calling user. `sudo -E` allows us to pass environmental variables through sudo. Here is an example:
ben@******:~$ sudo -E whoamiThe problem with doing this in Perl however seems to be that when you do a system() call, Perl opens a new subshell, which for some reason recognizes the $USER environmental variable as 'root', though it keeps some of the other variables.
root
ben@******:~$ sudo -E echo $USER
ben
To work around this issue, we can do as follows:
#!/usr/bin/perlNow the subscript can determine who the "backup" user is in a fairly agnostic way, and just grant permissions, rather than smiting the directory itself. It performs the minimum necessary action with superuser privileges, which should be the goal.
# script.pl
use strict;
$ENV{'IAM'} = $ENV{'USER'};
system('sudo -E /usr/local/bin/subscript.pl');
...
#!/usr/bin/perl
# subscript.pl
use strict;
my $iam = `echo -n \$IAM`;
say $iam;
You can even `chmod` subscript.pl to 750 and then just add an entry to your /etc/sudoers file like this:
backup ALL=(ALL) SETENV:NOPASSWD: /usr/local/bin/subscript.plI'm certain it would be possible to lock this process down even more if necessary. Your mileage may vary with older versions of sudo.
Tuesday, June 14, 2011
In case of F5 break glass
while true; do renice -15 `ps ax | grep cgi | awk '{print $1}' | xargs`; sleep 5; doneA one-liner that has helped me out. Force throughput on a named process, in this case, processes containing the string "cgi" in their name.
Saturday, June 11, 2011
PPTP VPN with Android + m0n0wall
So I finally got the chance this past week to play around with a beefy network device given to me by my friend, Michael Adams, about 3 or 4 years ago. More after the jump.
Monday, May 16, 2011
No place like 127.0.0.1
Work is keeping me very busy, but things are ok. Just about debt-free and happy.
Keeping a grip on home with this two-liner:
There's many different ways to accomplish this, and yes, I could use the full domain, but there's something nice about having 'home' in your hosts. You could also easily replace that first line with `cat ~/dropbox/homeip.txt` or `last -i | grep -v ':0\|0\.' | awk '{print $3}' | sed '/^$/d' | tail -n 1` or any other manner of magic to obtain your likely home IP.
Keeping a grip on home with this two-liner:
#!/bin/shexport home="`nslookup username.dyndns.org | grep Address | tail -n 1 | awk '{print $2}'`";
sed -i "s/^.*\shome/$home\t\thome/" /etc/hosts;
There's many different ways to accomplish this, and yes, I could use the full domain, but there's something nice about having 'home' in your hosts. You could also easily replace that first line with `cat ~/dropbox/homeip.txt` or `last -i | grep -v ':0\|0\.' | awk '{print $3}' | sed '/^$/d' | tail -n 1` or any other manner of magic to obtain your likely home IP.
Saturday, March 19, 2011
Migrating from Thunderbird to Outlook
Migrating archived email from Thunderbird into Outlook 2010 is not a trivial task. Outlook is not capable of importing from Thunderbird directly, so a little bit of convoluted work is necessary in order to get the mail imported correctly.
Start by downloading a utility like IMAPSize to convert Thunderbird's native MBOX format into EML format. After generating your archive of EML files is a good time to transport them to another machine if necessary.
Following this, you will need to import the EML files into Windows Live Mail as, if I recall correctly, "Windows Mail" files. Once you have successfully imported the files into Windows Live Mail, exporting them as "Exchange Export" should drop them directly into Outlook if you leave the default profile settings.
Good luck.
http://www.mozillamessaging.com/en-US/thunderbird/
http://office.microsoft.com/en-us/outlook/
http://www.broobles.com/imapsize/
Start by downloading a utility like IMAPSize to convert Thunderbird's native MBOX format into EML format. After generating your archive of EML files is a good time to transport them to another machine if necessary.
Following this, you will need to import the EML files into Windows Live Mail as, if I recall correctly, "Windows Mail" files. Once you have successfully imported the files into Windows Live Mail, exporting them as "Exchange Export" should drop them directly into Outlook if you leave the default profile settings.
Good luck.
http://www.mozillamessaging.com/en-US/thunderbird/
http://office.microsoft.com/en-us/outlook/
http://www.broobles.com/imapsize/
Subscribe to:
Posts (Atom)


