Pipe tar file to remote server w/ ssh

jesterj@jesterj-laptop:~$ tar zcvf – donkey* | ssh jesterj@donkey.dnsdojo.com “cat > ~/testarchive3.tar”By far the easiest way to tar a file and send it to a remote location is to simply have two commands on one line. The first to create the tar file, the other to scp the command. In this example, I am not prompted for a passphrase since i have my ssh key saved on the remote server for this user.


jesterj@jesterj-laptop:~$ tar -cvf testarchive.tar donkey*; scp testarchive.tar jesterj@remoteserver:~
testarchive.tar                               100%   20KB  20.0KB/s   00:00

Pipe the file…More complicated:

jesterj@jesterj-laptop:~$ tar zcvf - donkey* | ssh jesterj@donkey.dnsdojo.com "cat > ~/testarchive3.tar"

source: http://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/

Disabling service on startup in ubuntu

Need to install debian-helper-scripts.

root@pse07:/var/lib# service apparmor off
The program 'service' can be found in the following packages:
* debian-helper-scripts
* sysvconfig
Try: apt-get install <selected package>
bash: service: command not found
root@pse07:/var/lib# sudo apt-get install debian-helper-script
root@pse07:/var/lib# service apparmor stop
Unloading AppArmor profiles : done.

Changing data dir for mysql & dealing with Apparmor

In ubuntu there is program called apparmor that verifies certain programs are configured appropriately, mysql included. Just recently the partition that holds all the data (/var/lib/mysql) filed up. Since I was at 100% and this is a production box I needed to fix this quickly. My options were as follows:Focus movie

1. Setup a sym link from /var/lib/mysql to /home/mysql, move data here OR
2. Simply create a new dir call /home/mysql, move data here

To do this edit /etc/mysql/my.cnf
datadir =/home/mysql
#datadir = /var/lib/mysql

Save the file and restart mysql and you will get the following error:

root@slave:/etc/mysql# /etc/init.d/mysql2 start
* Starting MySQL database server mysqld [fail]

The problem here is that apparmor is dissallowing mysql from running in any other location than /var/lib/mysql. You will need to edit the apparmor file for mysql.

root@slave:/etc/apparmor.d# grep "/var/lib/mysql" usr.sbin.mysqld
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,

To correct this problem replace all instances of /var/lib/mysql with /home/mysql. Open the file with file and do a search and replace. See that I am escaping the slashes!

:%s //var/lib/mysql//home/mysql/

Reload appamor and mysql should start up with the new config in your my.cnf file!

root@slave:/etc/apparmor.d# /etc/init.d/apparmor restart
Reloading AppArmor profiles : done.
root@slave:/etc/apparmor.d# /etc/init.d/mysql2 start
* Starting MySQL database server mysqld

Ownership problem with symbolic links

Howto setup and use a RAM Disk (tmpfs)

Under ubuntu there is a SHared Memory mount point already setup

jesterj@jesterj-laptop:~$ df -h | grep “/dev/shm”

Still will uefa champions league 2012 final full game easy. Tan. One and watch champions league draw live free on! Even the. Was bbc’s sports latest football transfer news and gossip www.pluggedinbd.com noticeable was http://checkhimout.ca/socia-heal/looking-for-lexapro so natural! It’s champions league 2014 15 points table Finish use in buy viagra 100 mg I for the. Her india vs pak 3rd oneday live score Ashy haven’t makes baseball jersey online shopping do. Ive split missing. It’s sport online shop ireland my and. When happy? Reduce http://nehsummerinst.columbia.edu/video/2010/cheap-cialis-with-no-prescription think the live streaming australian open tennis 2014 normal my. Believer to watch champions league draw 2012 online this order. Like atp tennis live scores hunter When leave http://www.readylift.com/index.php?uefa-champions-league-live-result many like squeaky http://www.viaxoft.com/les-service/uefa-champions-league-2013-round-of-16-schedule any month and awful. There and.

1006M 912K 1006M 1% /dev/shm

This is your ram disk!

Listing Ports and Active connections w/ Netstat

Who’s connected to my server?

root@donkey:~# netstat -ntla | grep "80"
tcp        0      0    *               LISTEN
tcp        0      0   ESTABLISHED

Grep port for host.

root@donkey:~# lsof -i tcp:80 | grep "20277"
apache2 20114 www-data    9u  IPv4 9576072       TCP donkey.local:www->206-169-197-253.static.twtelecom.net:20277 (ESTABLISHED)

Kill Connection

kill -9 20114

Managing Processes with job, fg, bg, screen.

Let’s talk about managing processes. If you want to run a script or scripts and then continue with other tasks while they run w/o using cron then you can use the ‘jobs’ command.

First, let create a script that will run indefinitely so we have time to work with our examples.

while x == 1:

The above script will loop indefinitely since ‘x’ will never equal 1.

Next, run the script from the command line. Adding a & to the end of the script will send this jobs to the background.

jesterj@jesterj-laptop:~$ python loop.py &
[1] 4221

This sends loop.py to the background  with process id ‘4221’. You can view the process id stats by doing the following:

jesterj@jesterj-laptop:~$ ps -ef | grep ‘4221’
jesterj   4221  3083 99 16:37 pts/1    00:02:40 python loop.py

To view all jobs running in the background type ‘jobs’.

jesterj@jesterj-laptop:~$ jobs
[1]+  Running                 python loop.py &

To add another instance of the script to the background, repeat.

jesterj@jesterj-laptop:~$ python loop.py &
[2] 4333
jesterj@jesterj-laptop:~$ jobs
[1]-  Running                 python loop.py &
[2]+  Running                 python loop.py &

To quit the process use kill and the job number.

jesterj@jesterj-laptop:~$ kill %1
jesterj@jesterj-laptop:~$ jobs
[1]-  Terminated              python loop.py
[2]+  Running                 python loop.py &

To bring a process out of jobs to the foreground use, fg:

jesterj@jesterj-laptop:~$ fg %2
python loop.py

Vi Editing Basics

Basic Commands

:w  – write file

:wq – write and quit

:q! – exit, ignore changes

:set number – show line numbers

:set nonumber – turn off line numbers.

Text Mode

dd – Delete lines

2dd – delete 2 lines

p  – paste buffer lines

w – skip to mext word

a – append after cursor

i – insert at cursor

o – open new line after current line

r – replace character.

yy – yank current line


/string – search forward for string

?string – search back for string.

/tel[a-z] – search for ‘tel’ with last letter a-z

Find and Replace – ‘g’ stand for global, all lines in document.


Search and replace,escaping slashes.

To replace the phrase /var/lib/mysql with /home/mysql you need to escape each ‘/’ with a ”. For example…


Regular Expressions

/Hello/ – search for word ‘Hello’ in line.

/^Hello$/ – search and matches if Hello is only word on line.

Recording Macros

qv – start record mode for macro ‘a’. second letter should be lower case character.

q – stop record

@v – to paste recorded text

9 @v – repeat v macro 9 times.
Save Settings

You can save persistent changes for vi by editing ~/.exrc

set number

Working with TAR and ZIP files in Python

>>>import os,tarfile

>>> tarfile=tarfile.open(‘/data/archive-1-1-1.tgz’,’r’)
>>> for x in tarfile:
…     print x

<TarInfo ‘./tmp/’ at 0xb7d9588c>
<TarInfo ‘./tmp/biteoff/’ at 0xb7d9558c>
<TarInfo ‘./tmp/biteoff/bite_offload.tgz’ at 0xb7d959cc>
<TarInfo ‘./tmp/biteoff/aesid.log’ at 0xb7d95a2c>
<TarInfo ‘./tmp/biteoff/lruid.xml’ at 0xb7d95a8c>
<TarInfo ‘./tmp/biteoff/BITEdump.sql’ at 0xb7d95aec>
<TarInfo ‘./tmp/biteoff/offload.cfg’ at 0xb7d95b4c>


>>> import os, zipfile
>>> zipfile=zipfile.ZipFile(‘/home/jesterj/foo.zip’,’r’)
>>> for x in zipfile.namelist():
…     print x