Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, January 16, 2013

Capistrano with sudo

Capistrano with sudo

An easy way to execute commands with sudo from within a capistrano job is to add the prefix  #{sudo} to a command within your capistrano task.  For example:

task :make_protected_dir, :roles =>db do
  run "#{sudo} mkdir /root/mydir"
end

Another example:
task :restart_httpd, :roles =>app do
  run "#{sudo} /etc/init.d/httpd restart"
end

Then from the command line, load your file with these entries:

cap -f capfile

Then, execute the commands:

cap make_protected_dir

cap restart_httpd

More info:

https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Tasks-Task

Tuesday, January 1, 2013

S3 Utility

Here is a great tool for working with Amazon S3.  It even has a wide variety of repos available (easier than compiling from source).  s3cmd is very easy to setup.  It is the easiest to work with of all the S3 tools I have used.

Monday, March 26, 2012

Linux Mint on Gigabyte GA-Z68X-UD3H-B3

I tried to install Linux Mint on a desktop with Gigabyte GA-Z68X-UD3H-B3 motherboard with its Intel raid array configured with two of three hard drives.  I wanted to install Linux Mint 12 x64 on the third drive.  When trying to boot, I got the error message:

udev timeout killing /sbin/modprobe -bv pci:

I had to add the grub option of nomodeset as a kernel paramater.  It then was able to install from there.  Here are more details:

http://forums.linuxmint.com/viewtopic.php?f=46&t=95351&p=547012#p545731

Thursday, February 23, 2012

pv

This was so good I had to repost it here.  It is about a useful utility called pv which shows a progress report of running processes:

http://www.dp.cx/blog/pv--one-of-the-most-useful-applications-around.html

Monday, October 31, 2011

Visual explanation of SQL joins

I wish I had these pictures in my head when I started learning about joins in SQL.  Might have been a DBA instead of a systems engineer.


http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

Sunday, October 9, 2011

Charge iPad or iPad2 over usb in Linux

First, follow these instructions:

http://korenkov.info/ipad-ipad2-charge-ubuntu

For later versions of udev (I tested this on Ubuntu 11.04), make sure that /etc/udev/rules.d/95-ipad_charge.rules looks like the following examples.

For iPad:

ENV{DEVTYPE}=="usb_device", ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="129a", RUN+="/usr/bin/ipad_charge"

For iPad2:

ENV{DEVTYPE}=="usb_device", ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="129f", RUN+="/usr/bin/ipad_charge"

Then restart udev or reboot.

Wednesday, October 5, 2011

Monday, April 18, 2011

Sending files from the Linux command line

Here is a quick way to e-mail yourself files from a server using mutt.

$ mutt -a tcpdumpApril182011.pcap my_name@example.com < /dev/null

Mutt is great for sending MIME encoded files.

Wednesday, November 17, 2010

Bash for loops with a series of numbers or letters

Bash scripting is great. Here is a quick trick to funnel a series of numbers (or letters) into a variable, and thus an argument of a script:


#!/bin/bash
for a in {1..18}
do
echo "The number $a"
done


#!/bin/bash
for a in {a..z}
do
echo " The letter $a "
done

Here is another example:

for a in {0..15};  do  /usr/sbin/xm vcpu-pin 0 $a 0-1,4-15;  done


Such a quick and easy trick!

Thursday, July 22, 2010

Bring Netflix streaming to Linux!

Considering there are a host of devices (PS3, Roxee, TiVo, LG Blu-Ray players) that run Linux internally and support Netflix Streaming, it should be an easy technical transition to bring this to Linux.  Sign the petition to bring Netflix streaming to Linux. I am promoting it so I can use Netflix Streaming on my MythTV server and enhance the MythTV experience with Netflix streaming.

http://www.petitiononline.com/Linflix/petition.html

Thursday, May 27, 2010

Write on my Linux wall

To display a text message to other users logged into a *nix system, use the wall command. For example:

wall "Deploying new .ear file in five minutes."


This will send the message to all users logged into the system, whether they be physically on a console, via ssh or ftp.

Monday, September 28, 2009

Determine BIOS settings within Linux

Use dmidecode to determine hardware information fro the system EFI or BIOS.

Thursday, September 24, 2009

Process affinity

Here is how to bind a program to a CPU (process affinity):

Bind processes to a CPU core

An example would be:

taskset -pc 0,1,2 20509

to set processid #20509 to have affinity (bind) on Cpu0, Cpu1, and Cpu2. To bind it to a single core, use the command:

taskset -pc 0 20509

to bind it to Cpu0.

Thursday, June 4, 2009

Quicky find what directories are using up space on your disk

The df -h command will tell you disk usage from a mountpoint perspective, but the command du tells you from a directory perspective. Use the command:

du -h / --max-depth=1

To show disk usage for each individual directory on the system, or go lower down to see usage on a particular directory:

du -h /var/log --max-depth=1

Wednesday, April 1, 2009

zipidey-do daw, zipidey-de day, what a wonderful day!

The zip command will create a zip file that can be used across disparate platforms, including Linux/Unix to Windows or Mac. In other words, if you need to send your Windows friend several ziped files and he can only deal with .zip files, keep it simple. Don't use bzip or tar, just use zip. Here is a command to create a highly compressed zip file to contain some log files. Then just get the produced zipfile to your Windows "without walls" friend.

zip -9 logServices.zip /var/log/messages myapp/logs/mylog.log /usr/local/tomcat/logs/catalina.out

Add an temporary user account

If you need an account for a set period of time, or an account that you don't want to deactivate later, add the -e option on useradd:

useradd -m -e 2009-12-01 -c "Temp Account" tempUser

This user account will expire on December 1st, 2009 and will lock the user and their password.

Thursday, March 26, 2009

Tar with date and a twist of chocolate

Here is a way to tar up a set of important directories with the date. You can use this as a log archive, or with Splunk. This uses the highest compression of gzip (-9).

tar cp /myapp/logs /var/log/messages /var/log/httpd/ | gzip -9c > /tmp/oldlogs`date +"%Y%m%d"`.tgz

Monday, March 23, 2009

Reboot your computer after 4082.97902312 years

For some cool reason, the maximum time that the Linux shutdown command will accept is 2,147,483,647 minutes, which is 4082.97902312 years. If you think your hardware is going to last that long, execute the command:

#shutdown -r -F 2147483647

In a little over 4,000 years, it will reboot and check your disks. Hopefully by then you will be doing something cooler than counting down, like golfing on Mars.

Tuesday, February 10, 2009

Unique lines in a file

If you want to see all unique lines within a file, use the uniq command within Linux/Unix. To do so, just execute uniq against a file.

#uniq /var/log/messages

Or, less elegantly...

#cat /var/log/messages | uniq

This will also work with standard input.

Friday, January 16, 2009

Quick and dirty openLDAP replication

This is a cursory view of how to install and configure a master and slave openLDAP server pair. Unless specified, follow each step on both the master and the slave servers. The only real difference between the servers is the presence of a slurpd configuration on the master and the unique slapd configuration on both servers. In the end, you will have a syncing pair which will replicate changes from the master server to the slave server every three seconds.

A. Install OS and LDAP

1.Install your OS. I am assuming Linux, specifically RHEL or Fedora Core, but openLDAP will run on a variety of systems and these instructions can be adapted to your specific flavor.

2.On both the master and the slave, install openldap, php, httpd and the dependencies with the command (assuming RHEL or Fedora Core):
# yum -t -y install openldap-clients openldap-servers openldap php-ldap nss_ldap httpd php

B. Install and configure phpLDAPadmin (optional)

3.Install phpLDAPadmin from this website: http://phpldapadmin.sourceforge.net/wiki/index.php/Main_Page

4.Untar the download, and then copy the file phpldapadmin-<version>/config/config.php.example to phpldapadmin-/config/config.php

5.Move the phpldapadmin-<version> to /var/www/html/phpldapadmin

6.Restart httpd with the command
#chkconfig httpd on
#service httpd restart

C. Configure and test LDAP

7.Make sure that the master server's hostname is pingable from the slave and vice versa. If not, add the entries to /etc/hosts and restart networking with the command:
#service network restart

8.Copy /etc/openldap/ldap.conf to /etc/openldap/ldap.conf.orig

9.Copy /etc/openldap/sldapd.conf to /etc/openldap/slapd.conf.orig

10.Copy /etc/openldap/DB_CONFIG.example to /var/lib/ldap/DB_CONFIG

11.Copy the configuration files to the respective servers. These are located at the bottom of this document. Make sure to copy the correct ldap.conf and slapd.conf to their respective servers.

12.Import the base dn from the base.ldif file (included later in this document)
#slapadd < /etc/openldap/base.ldif

13.Start the LDAP service
# chkconfig ldap on
# service ldap start

14.Point to http://hostname/ or http://hostname/phpldapadmin If you get a “php memory too low” error, change the memory limit to something meaningful in /etc/php.ini
memory_limit = 128M ; For example

15.The login for the server is cn=root,dc=example,dc=com and the password needs to be set with slappasswd. Use slappasswd and change the hash in the /etc/openldap/slapd.conf file.
# slappasswd
New password:
Re-enter new password:
{SSHA}At/pOvtko2KXcKfM7t0o/OPedJrpXQM0

Now enter the line with the hashed password in the file /etc/openldap/slapd.conf as shown:
rootpw {SSHA}At/pOvtko2KXcKfM7t0o/OPedJrpXQM0

16.From the phpLDAPadmin GUI or using #slapadd similar to before, import the ldif file from a backup or existing server to the master server. If you have not created or do not have a backup of the ldif file of the old directory server, the other option is to copy the /var/lib/ldap directory over to the new server. If starting from scratch, this is a mute point.

17.If syncing is working, it will be replicated on the slave server. If not, the file /var/lib/ldap/replica/openldap-master-replog on the master server will tell you why.

18.For testing the syncing and replication of the master and slave servers, add a new entry to the master server and see if the entry appears on the slave server. For testing the subordination of the slave server, create an entry on the slave server and watch as it is not replicated on the master server.

/etc/openldap/base.ldif (For both servers)
dn: dc=example,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
dc: example
o: Example

/etc/openldap/ldap.conf (For master server)
URI ldap://127.0.0.1/
BASE dc=example,dc=com
TLS_CACERTDIR /etc/openldap/cacerts

/etc/openldap/slapd.conf (For master server)
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
allow bind_v2
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
#Note that this should be changed based upon the hostname or user for greater security
access to *
by * read
by anonymous auth
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
# rootdn can always read and write EVERYTHING!
database bdb
suffix "dc=example,dc=com"
rootdn "cn=root,dc=example,dc=com"
rootpw {SSHA}/mYjTZhwSR1hIGKt6qD0oBpHdRjeHSGh
directory /var/lib/ldap
index objectClass eq,pres
index ou,cn,mail,surname,givenname eq,pres,sub
index uidNumber,gidNumber,loginShell eq,pres
index uid,memberUid eq,pres,sub
index nisMapName,nisMapEntry eq,pres,sub
# Replicas of this database
replogfile /var/lib/ldap/openldap-master-replog
replica host="slave:389"
suffix="dc=example,dc=com"
binddn="cn=root,dc=example,dc=com"
credentials=changeme
bindmethod=simple

/etc/openldap/ldap.conf (For slave server)
URI ldap://127.0.0.1
BASE dc=example,dc=com
TLS_CACERTDIR /etc/openldap/cacerts
updatedn "cn=root,dc=example,dc=com"
updateref ldap://master
rootdn "cn=root,dc=example,dc=com"
rootpw {SSHA}nlb8tJHDUJCMqQMBMyMIIu26VF1ViVEu

/etc/openldap/slapd.conf (For slave server)
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
allow bind_v2
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
# Note that you should change this based upon the hostname of the master server.
access to *
by * write
by anonymous auth
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
# rootdn can always read and write EVERYTHING!
database bdb
suffix "dc=example,dc=com"
rootdn "cn=root,dc=example,dc=com"
rootpw {SSHA}/mYjTZhwsR1hIGKt6qD0oBpHdRjeHSGh
updatedn "cn=root,dc=example,dc=com"
updateref ldap://master
directory /var/lib/ldap
index objectClass eq,pres
index ou,cn,mail,surname,givenname eq,pres,sub
index uidNumber,gidNumber,loginShell eq,pres
index uid,memberUid eq,pres,sub
index nisMapName,nisMapEntry eq,pres,sub
TLSCertificateFile /etc/openldap/ldap.cert
TLSCertificateKeyFile /etc/openldap/ldap.key