Linux list openports with processes names    Posted:


netstat -putln

-p the PID and name of the program to which each socket belongs.

-u udp

-t tcp

-l only listening sockets. (These are omitted by default.)

-n numeric port number

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
 Active Internet connections (only servers)
 Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
 tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
 tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -
 tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -
 tcp        0      0 127.0.0.1:5433          0.0.0.0:*               LISTEN      -
 tcp        0      0 0.0.0.0:902             0.0.0.0:*               LISTEN      -
 tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -
 tcp        0      0 0.0.0.0:9418            0.0.0.0:*               LISTEN      -
 tcp        0      0 127.0.0.1:2222          0.0.0.0:*               LISTEN      -
 tcp        0      0 0.0.0.0:9614            0.0.0.0:*               LISTEN      -
 tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
 tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN      -
 tcp6       0      0 :::22                   :::*                    LISTEN      -
 tcp6       0      0 ::1:631                 :::*                    LISTEN      -
 tcp6       0      0 :::25                   :::*                    LISTEN      -
 tcp6       0      0 :::9418                 :::*                    LISTEN      -
 udp     5376      0 0.0.0.0:5353            0.0.0.0:*                           2934/libpepflashpla
 udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -
 udp        0      0 0.0.0.0:46482           0.0.0.0:*                           -
 udp        0      0 0.0.0.0:631             0.0.0.0:*                           -
 udp6       0      0 :::5353                 :::*                                -
 udp6       0      0 :::57898

Comments

Linux diplay size of each subdirectory    Posted:


To display total size of each subdirectory

du -sh *

-h human readable displays MB and GB instead of milions and bilions of bytes :) -s summarize total size of dir

Comments

ssh reverse tunneling    Posted:


When you want someone to connect to your NAT-ed or Firewalled server and

you run out of ideas ond options or you even dont have

you dont have access to Firewall or VPN server to configure

anything - you can always try to use reverse ssh tunnel.

The only one condition is that you must be able to ssh from your server to public host( the one other guy wants to connect)

This is how it works:

[Server] <----> [ FIREWALL/NAT SERVER ] <----> [ BOB HOST with public ip 80.80.80.80]

Comments

Fabric    Posted:


fabric execution::::: fab -H me@host1,me@host2,me@host3 function

Example: fab -H greg@mmyserver.com get_backup

or alternatively:

Example: fab production1 deploy but then you'll have to production1 defined inside your fabfile.py
def production():
     env.update(dict(
         dest='production',
         hosts=['some_ip_address'],
 ))

 def development():
     env.update(dict(
         dest='development',
         hosts=['localhost'],
 ))

local - execute a local command means host from which we launch fabric

run - execute a remote command on all specified hosts, user-level permissions

sudo - sudo a command on the remote server)

put - copy over a local file to a remote destination)

get - download a file from the remote server)

prompt - prompt user with text and return the input (like raw_input))

reboot - reboot the remote system, disconnect, and wait for wait seconds)

Download some logs

get(remote_path="/tmp/log_extracts.tar.gz", local_path="/logs/new_log.tar.gz")

Comments

Python combine dates , current date with different hour    Posted:


Specification: I want to launch deployment script but not before 18:00 so every user can leave home. I want to lunch it today but with different time that datetime.datetime.now() gives To do it I think best way is t to combine date.today with time(18,00) and then compare with datetime.now() Command of lauching is up to us so jsut for tests lets pass it in argvs:

python testtime.py 16 35
import sys
from datetime import datetime, date,time

current_time=datetime.now()
ehour=int(sys.argv[1])
eminute=int(sys.argv[2])

exe_time=datetime.combine(date.today(), time(ehour,eminute))
#or datetime.(datetime.today().year,datetime.today().month,datetime.today().day,ehour,eminute)
print "time left:"
print (exe_time - current_time)

if exe_time<=current_time:
    print "executing..."

Comments

git_notes    Posted:


git diff --cached /what is about to be committed git status brief summary of the situation with git log At any point you can view the history of your changes usingggit log -pit log -p

git log -pIf you also want to see complete diffs at each step, use

git log --stat --summaryOften the overview of the change is useful to get a feel of each step:w

remove wrongly commited large files ➜ my_project git:(master) ✗ git filter-branch --tree-filter 'rm -rf site_media/help' HEAD Rewrite 22d1cead6a67d68939da2eef48c5372b36651a5c (70/70) Ref 'refs/heads/master' was rewritten

restore deleted uncommited file git status git checkout -- filename

The output tells you what you need to do. git reset HEAD cc.properties etc.

This will unstage the rm operation. After that, running a git status again will tell you that you need to do a git checkout -- cc.properties to get the file back.

Update: I have this in my config file

$ git config alias.unstage reset HEAD which I usually use to unstage stuff.

Comments

pycurl_problem    Posted:


(flats)➜  projects  pip install pycurl
 Downloading/unpacking pycurl
   Downloading pycurl-7.19.3.1.tar.gz (116kB): 116kB downloaded
   Running setup.py (path:/workspace/virtualenvs/flats/build/pycurl/setup.py) egg_info for package pycurl
     Traceback (most recent call last):
       File "<string>", line 17, in <module>
       File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 563, in <module>
         ext = get_extension()
       File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 368, in get_extension
         ext_config = ExtensionConfiguration()
       File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 65, in __init__
         self.configure()
       File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 100, in configure_unix
         raise ConfigurationError(msg)
     __main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory
     Complete output from command python setup.py egg_info:
     Traceback (most recent call last):

   File "<string>", line 17, in <module>

   File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 563, in <module>

     ext = get_extension()

   File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 368, in get_extension

     ext_config = ExtensionConfiguration()

   File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 65, in __init__

     self.configure()

   File "/workspace/virtualenvs/flats/build/pycurl/setup.py", line 100, in configure_unix

     raise ConfigurationError(msg)

 __main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory

 ----------------------------------------
 Cleaning up...
 Command python setup.py egg_info failed with error code 1 in /workspace/virtualenvs/flats/build/pycurl
 Storing debug log for failure in /home/greg/.pip/pip.log
 (flats)➜  projects  pip install pycurl

Solution:

apt-get install libcurl4-gnutls-dev librtmp-dev

Comments

rerun    Posted:


Write your post here.

Comments