Posts Tagged ‘ssh’

python tricky way

marzo 23, 2012 Commenti disabilitati

I’m using python for several script this days and I’m figured out how much is powerful compared to the bash script language. So I’ve decided to write here some script or some fuzzy trick to get easy the sysadmin’s life .

Also it is a good way to start writing some code and get out from the secure shell scripting and copy-edit-pasted-perl-code.

Python is different …


First of all let me try to explain why python .

python is a very simple language, it is intuitive and for who knows different program languages you will feel secure, quick and easy to learn. Sure it has some syntax limit, but is a chooice. I’ve spent more the few weeks to understand why there is the need to indenting the code, then I’ve understood it… It’s for the one who read the code.. not only for who stay writing everyday!

The limit of python is the result of his powers!

There is no need to define new vars, or to repeat some code, because create a function is very quickly and finally let me see it: the world is better without brackets


Take a look at this:

# s@mba - python & pexpect
# python simple ssh connection withouth password
import pexpect

myhost = "user@machiname.lan"
commands = ["ls","uptime","some other fucking commands", "exit"]
p = pexpect.spwan("ssh " + myhost)
conn = p.expect(["Are you sure","[Pp]assoword",pexpect.EOF])
if conn == 0:
if conn == 1:
  passw = raw_input("Password: ")
if conn == 2:
  sys.exit("no ssh session, exit")
for cmd in commands:
print p.before

This is a very simple way to execute some code on a remote server if you cannot store ssh_keys in authorzed_keys, easy no?

Why using pexpect and not expect language?

Beacuse in this way I can manage all the exception, timeout and other issue just using the “try:” option in python

So stay tuned sysadmin, probably you will find something interesting, maybe some fuzzy scripts¬† about python ūüôā

you know a good sysadmin always finding a way to solve, workaround and automatize all the mountain of problem here we have

and if you really don’t know nothing about it, it could be a good way to start.


Categorie:varie Tag:, , , ,


giugno 21, 2009 2 commenti

# ssh root@sarcazzo

RSA key fingerprint is 03:83:92:44:9c:6f:25:97:fb:cd:4f:00:bc:e0:e0:80.
Are you sure you want to continue connecting (yes/no)? y
Please type ‚Äėyes‚Äô or ‚Äėno‚Äô: yes

Are you sure you want to continue connecting (yes/no)?



La paranoia, sto sbabbiando, non capisco pi√Ļ un cazzo….

tastiera sun-type5 (no mouse, no copia&incolla):


tnx to:

Categorie:linux, varie Tag:, , , , ,


febbraio 14, 2009 Commenti disabilitati

Sto usando spesso screen in ambito server e diventa sempre pi√Ļ utile utilizzare un unico screenrc fatto per bene.

Screen √® un multiterminale creato proprio per chi ha la necessit√† di avere pi√Ļ di una console aperta e switchare spesso da una all’altra. Permette di spostarsi senza utilizzare il mouse e grazie a tantissime scorciatoie da tastiera si possono eseguire comandi complicati in un attimo. La sua natura ricora molto vim, ma la sua potenza √® nulla senza il controllo!

Quindi posto qui di seguito un ottimo screenrc:

# s@mba ~/.screenrc
# file di configurazione di screen
autodetach            on             
crlf                  off            
deflogin              off            
hardcopy_append       on             
startup_message       off     
termcapinfo linux "ve=\E[?25h\E[?17;0;64c" # red
vbell                 off             
defscrollback         3000            
silencewait           15              
shell                 bash
# in order to print
caption always "%{= kw}%?%-Lw%?%{+b kw}%n*%t%f %?(%u)%?%{= kw}%?%+Lw%?"
hardstatus alwayslastline "%{+b kr}[ %H ] %{ky} Load: %l %-=%{kb} %c  %d.%m.%Y"

sorendition gK
activity              "activity in %n (%t) [%w:%s]~"
bell                  "bell     in %n (%t) [%w:%s]~"
pow_detach_msg        "BYE"
vbell_msg             " *beep* "
bind A title  # default!
bind ^g  screen -t 'Google' links
bind K  kill # default!
bind M monitor # default!
bind P paste .
bind V screen -t 'vim' 0 vim
bind ^Y screen -t log watch -n 5 rail -40 /var/log/syslog
bind .
bind ^\
bind \\
msgwait 1
msgwait 2
echo "Benvenuto :-)"

Per la verione originale e sopratutto commentata fare rifermento a questo esempio completo di screenrc

Categorie:varie Tag:, , , , ,