Posts

Showing posts from August, 2011

[Level 1] Make Nautilus always use Location Entry in Ubuntu 10.04

Hi all: FYI. http://ubuntuguide.net/make-nautilus-always-use-location-entry-in-ubuntu-10-04 Wish this helps. regards, Stanley Huang

[Level 1] Install autoexpect

$ autoexpect -f ./auto.exp autoexpect started, file is ./auto.exp $ ssh stanley@localhost The authenticity of host 'localhost (127.0.0.1)' can't be established. RSA key fingerprint is 36:12:a4:49:26:fe:18:0d:77:bf:c7:e8:36:86:b7:f2. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'localhost' (RSA) to the list of known hosts. stanley@localhost's password: Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-generic x86_64) * Documentation: https://help.ubuntu.com/ *** /dev/sda5 will be checked for errors at next reboot *** Last login: Thu Jul 28 12:17:50 2011 from stanley-ubuntu $ ls apache-cassandra-0.8.1-SNAPSHOT.jar Public auto.exp Rock Desktop script.exp Documents scripts Downloads scripts_20110302.tgz eclipse Self_assesment_201103.pdf English_Survey.pdf SUR-1-Vesu_Pi

[Level 2] How to simulate udevinfo in Ubuntu 11.04

When you try to use command udevinfo in Ubuntu 11.04, you would get the response "udevinfo: command not found". How to simulate the command udevinfo? Use command udevinfo with info option. Ex. # udevadm info -q all -n /dev/video0 You could also create a function named udevinfo as you like Ex. # udevinfo () { udevadm info -a -p `udevadm info -q path -n "$1"`; } # udevinfo /dev/video0 ... Wish this helps. regards, Stanley Huang

[Level 2] python oui lookup

$ sudo apt-get -y install python-netaddr ... $ cd /usr/share/pyshared/netaddr/eui $ sudo python ./ieee.py downloading latest copy of http://standards.ieee.org/regauth/oui/oui.txt downloading latest copy of http://standards.ieee.org/regauth/oui/iab.txt $ python >>> from netaddr import * >>> mac = EUI('bc:ae:c5:3b:fc:5e') >>> print mac.oui.registration().org ASUSTek COMPUTER INC. Wish this helps. regards, Stanley Huang

[Level 2] Use expect to run openvpn.

#!/usr/bin/expect set password [lindex $argv 0] spawn sudo openvpn --script-security 2 --config /home/stanley/VPN/MyVPN_config/MyVPN.ovpn expect Enter\ Private\ Key\ Password: sleep 1 send $password sleep 1 interact Test run: # ./openvpn.expect mypassword Wish this helps.  regards, Stanley Huang

[Level 2] Pexpect of Python.

#!/bin/env python import os, sys import StringIO class AuthorizedKeyError(Exception): def __init__(self, host): self.value = 'Did not be authorized by remote server(%s)!!!' % host def __str__(self): return repr(self.value) class FileSyncManager: def fileSync(self, user, host, file): output = StringIO.StringIO() sCmd = 'scp %s %s@%s:%s' % (file, user, host, file) self.debug(sCmd) scp = pexpect.spawn(sCmd) scp.logfile = output while True: index = scp.expect(["Are you sure you want to continue connecting (yes/no)?", "password:" ,pexpect.TIMEOUT, pexpect.EOF]) if index == 0: scp.sendline('yes') elif index == 1: raise AuthorizedKeyError(host) else: break if scp.exitstatus: error_message = outpu

[Level 2] How to skip StrictHostKeyChecking in ssh.

If you want to ignore strict host key checking, even skip saving the host key info, you could use option UserKnownHostsFile, StrictHostKeyChecking. Ex. ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no stanley@192.168.1.1 or modify /etc/ssh/ssh_config for global settings. # cat /etc/ssh/ssh_config ... UserKnownHostsFile /dev/null StrictHostKeyChecking no ... Wish this helps. regards, Stanley Huang

[Level 2] Recursive directory list

#!/bin/env python import os, sys wholeFileList = [] baseDir = sys.argv[1] for parentDir, childDirList, fileList in os.walk(baseDir): for file in fileList: wholeFileList.append(os.path.join(parentDir,file)) for file in wholeFileList: print file # ./t.py /tmp/d /tmp/d/1.txt /tmp/d/2/6.txt /tmp/d/2/3/a.txt /tmp/d/2/4/b.txt /tmp/d/2/5/c.txt Wish this helps. regards, Stanley Huang