Monday, 28 July 2014

Easiest way to force interface to full duplex on linux

sudo ethtool -s eth0 autoneg off speed 100 duplex full

this can be verified with

sudo ethtool eth0

and should report something like:

Settings for eth0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
    Supported pause frame use: Symmetric Receive-only
    Supports auto-negotiation: Yes
    Advertised link modes:  Not reported
    Advertised pause frame use: No
    Advertised auto-negotiation: No
    Speed: 100Mb/s
    Duplex: Full

    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: off
    MDI-X: Unknown
    Current message level: 0x000060e4 (24804)
                   link ifup rx_err tx_err hw wol
    Link detected: yes

Thursday, 17 July 2014

How to determine if filesystem or drive is mounted Read Only in linux

The easiest way is via the command line with:
grep "\sro[\s,]" /proc/mounts

And a further command line to see the mount points:
mount -v | grep "^/" | awk '{print "\nPartition identifier: " $1  "\n Mountpoint: "  $3}'

Thursday, 26 June 2014

QNAP TS-412 Firmware 4.0.2 to 4.0.7 upgrade


The web based upgrade for the firmware failed on this device; to manually do the upgrade follow this procedure:


remove all the update folders and then re-create one with a link to the other

download the firmware

make a copy of the file as the source will get removed during the upgrade (optional step)

[~] # rm -rf /mnt/HDA_ROOT/update/
[~] # rm -rf /mnt/update
[~] # mkdir /mnt/HDA_ROOT/update
[~] # ln -sf /mnt/HDA_ROOT/update /mnt/update
[~] # cd /share/Public
[/share/Public] # wget http://eu1.qnap.com/Storage/TS-412TurboNAS/TS-412_20140412-4.0.7.zip
[/share/Public] # unzip TS-412_20140412-4.0.7.zip
[/share/Public] # cd ~

[~] # cp /share/Public/TS-412_20140412-4.0.7.img /share/Public/TS-412_20140412-4.0.7-work.img
[~] # /etc/init.d/update.sh /share/Public/TS-412_20140412-4.0.7-work.img

this will have an output like
cksum=1718371300
Check disk space available for FW update: OK.
Using 120-bit encryption - (QNAPNASVERSION4)
len=1048576
model name = TS-412
version = 4.0.7
boot/
config/
fw_info
initrd.boot
initrd.boot.cksum
libcrypto.so.1.0.0
libssl.so.1.0.0
qpkg.tar
qpkg.tar.cksum
rootfs2.img
rootfs2.img.cksum
rootfs_ext.tgz
rootfs_ext.tgz.cksum
uImage
uImage.cksum
update/
update_img.sh
4.0.7 20140412
MODEL NAME = TS-412,new version = 4.0.7
limit version = 3.8.2
Allow upgrade
tune2fs 1.41.4 (27-Jan-2009)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
Update image using HDD ...
Check uImage size ... Pass
Check initrd.boot size ... Pass
Check rootfs2.img size ... Pass
Check Flash ROM
Update Kernel ...
Update Basic RootFS ...
Update Basic RootFS2 ...
1+0 records in
1+0 records out
Update Finished.
set cksum [1718371300]

then afterwords reboot
# reboot

Monday, 23 June 2014

How to set MTU on Linux interface



The MTU can be set with:
$ sudo ip link set dev tun0 mtu 1350

It can be tested with
$ ip a s 

And will show something like the below:
5: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1350 qdisc pfifo_fast state UNKNOWN group default qlen 100

link/none 

Friday, 20 June 2014

Ubuntu bulk rename files

If you don't want to use the command line to rename files the following application "pyrenamer" have a lot of functionality and work a charm.


With pyRenamer you can change the name of several files at the same time easily.
→ You can use patterns to rename files.
→ You can use search & replace to rename files.
→ You can use common substitutions.
→ You can manually rename selected files.
→ You can rename images using their metadata.
→ You can rename music using its metadata.

To install it:
sudo apt-get install pyrenamer

Friday, 6 June 2014

Ways to find your Public IP





Various ways exist for different purposes but I thought I will list a few ways to find the external IP.




In bash:

1:  IP=$(curl -s ifconfig.me)  
2:  echo “Your IP is $IP”  

In Python:

1:  import requests  
2:  r = requests.get(r'http://jsonip.com')  
3:  ip= r.json()['ip']  
4:  print 'Your IP is', ip  

Sites that return your external IP

http://ifconfig.me/ip

http://ipecho.net/plain

http://checkip.dyndns.org/plain

http://ipogre.com/linux.php

http://whatismyipaddress.com/

http://ip.my-proxy.com/

http://websiteipaddress.com/WhatIsMyIp

http://getmyipaddress.org/

http://showmyipaddress.com/

http://www.my-ip-address.net/

http://myexternalip.com/raw

http://www.canyouseeme.org/

http://www.trackip.net/

http://myip.dnsdynamic.org/

http://icanhazip.com/

http://www.iplocation.net/

http://www.howtofindmyipaddress.com/

http://www.ipchicken.com/

http://whatsmyip.net/

http://www.ip-adress.com/

http://checkmyip.com/

http://www.tracemyip.org/

http://checkmyip.net/

http://www.lawrencegoetz.com/programs/ipinfo/

http://www.findmyip.co/

http://ip-lookup.net/

http://www.dslreports.com/whois

http://www.mon-ip.com/en/my-ip/

http://www.myip.ru

http://ipgoat.com/

http://www.myipnumber.com/my-ip-address.asp

http://www.whatsmyipaddress.net/

http://formyip.com/

https://check.torproject.org/

http://www.displaymyip.com/

http://www.bobborst.com/tools/whatsmyip/

http://www.geoiptool.com/

https://www.whatsmydns.net/whats-my-ip-address.html

https://www.privateinternetaccess.com/pages/whats-my-ip/

http://checkip.dyndns.com/

http://myexternalip.com/

http://www.ip-adress.eu/

http://www.infosniper.net/

http://wtfismyip.com/

http://ipinfo.io/

http://httpbin.org/ip

Wednesday, 2 April 2014

SortTV - Sorting Movies

A application that can automatically sorts TV show episodes into an organised
directory structure. Can optionally move non-episodes into a separate directory. Also optional integration with xbmc (notification and library update).

Project located at : http://sourceforge.net/projects/sorttv/ at the time of writing the latest version was SortTV1.37

Download and extract the files and edit the configuration file (sorttv.conf)

most important values to set:
  • directory-to-sort=
  • tv-directory=
  • music-directory=
  • movie-directory=

and execute with perl;
perl sorttv.pl  or ./sorttv.pl

If you experience some errors it will be most likely perl libraries that are missing these can be installed with:

sudo apt-get install libwww-perl  
sudo perl -MCPAN -e 'install TVDB::API'  
sudo perl -MCPAN -e 'install WWW::TheMovieDB::Search'  
sudo perl -MCPAN -e 'install WWW::TheMovieDB'  
sudo perl -MCPAN -e 'install JSON::Parse'  

Titles can be substituted in the configuration file (sorttv.conf)

# Substitute the titles of these shows
show-name-substitute=CSI-->CSI: Crime Scene Investigation
show-name-substitute=CSI Crime Scene Investigation-->CSI: Crime Scene Investigation
show-name-substitute=Sanctuary US-->Sanctuary
show-name-substitute=Shit My Dad Says-->$#*! My Dad Says
show-name-substitute=ABC - Two and a Half Men-->Two and a Half Men
show-name-substitute=Its Always Sunny in Philadelphia-->It's Always Sunny in Philadelphia
show-name-substitute=American Dad-->American Dad!
show-name-substitute=Penn & Teller Bullshit!-->Penn & Teller: Bullshit!
show-name-substitute=Being Human UK-->Being Human
show-name-substitute=House MD-->House
show-name-substitute=House M.D.-->House
show-name-substitute=Game of Throne-->Game of Thrones
show-name-substitute=Star Trek DS9-->Star Trek Deep Space 9
show-name-substitute=Marvels Agents of S H I E L D -->Marvels Agents of S.H.I.E.L.D.

Spesific TVDB id's can be manually entered in the configuration file as well, for series that is incorrectly identified e.g.

# Use these tvdb IDs to lookup these shows
tvdb-id-substitute=$#*! My Dad Says-->164951
tvdb-id-substitute=$#-! My Dad Says-->164951
tvdb-id-substitute=Shit My Dad Says-->164951
tvdb-id-substitute:Brothers and Sisters-->79506
tvdb-id-substitute:Greys Anatomy-->73762
tvdb-id-substitute:David Letterman-->75088
tvdb-id-substitute:The Daily Show-->71256
tvdb-id-substitute:Conan-->194751
tvdb-id-substitute:Jay Leno-->70336
tvdb-id-substitute:Dont Trust the Bitch in Apartment 23-->248812
tvdb-id-substitute:True Detective-->270633
tvdb-id-substitute:The Tomorrow People US-->268591
tvdb-id-substitute:The Tomorrow People (US)-->268591
tvdb-id-substitute:Once Upon A Time-->248835
tvdb-id-substitute:Scandal-->248841

To make this task easier in ubuntu a Nautilus script can be created to add the sorttv command to the context menu (Right click > scripts)

Paste the following code into
~/.local/share/nautilus/scripts

or
right click > scripts > open scripts folder

then add the following code to a file and name it something that make sense e.g. Sorttv-Organiser
#!/bin/bash
notify-send "SortTV" "Script started to sort  " -i ~/Pictures/sorttv.png -t 500
/opt/applications/sorttv/sorttv.pl
notify-send "SortTV" "Script completed " -i ~/Pictures/sorttv.png -t 5000

in this example
notify-send is used to send a notification to the desktop and
/opt/applications/sorttv/ the location of sorttv application

Whenever you want to sort just right click in Nautilus and run the script


Tuesday, 4 March 2014

Cisco ASA 8.4 on GNS3 in Linux

Best recommendation would be to test the qemu image before moving it into GNS3.

To find the location of the binaries:

user@pc:~ > which qemu-img
/usr/bin/qemu-img

then

user@pc:~/Cisco/ASA_842 > /usr/bin/qemu-system-i386 -name ASA1 -m 1024 -kernel ./asa842-vmlinuz -initrd ./asa842-initrd.gz -append "ide_generic.probe_mask=0x01 ide_core.chs=0.0:980,16,32 auto nousb console=ttyS0,9600 bigphysarea=65536 ide1=noprobe no-hlt" -netdev user,id=mynet0 -netdev user,id=mynet1 -netdev user,id=mynet2 -netdev user,id=mynet3 -netdev user,id=mynet4 -netdev user,id=mynet5 -device e1000,mac=00:00:ab:1a:f2:00,netdev=mynet0 -device e1000,mac=00:00:ab:df:12:01,netdev=mynet1 -device e1000,mac=00:00:ab:7e:73:02,netdev=mynet2 -device e1000,mac=00:00:ab:1c:9d:03,netdev=mynet3 -device e1000,mac=00:00:ab:db:25:04,netdev=mynet4 -device e1000,mac=00:00:ab:69:d8:05,netdev=mynet5 -serial telnet:127.0.0.1:4444,server,nowait -vnc none -vga none -icount auto -hdachs 980,16,32 -cpu coreduo -nographic

and then log into the ASA router virtual image with : telnet localhost 4444

if working as expected configure Qemu in GNS3:

and then the ASA:

Qemu options : -vnc none -vga none -icount auto -hdachs 980,16,32 -cpu coreduo -nographic
Kernel Cmd Line : ide_generic.probe_mask=0x01 ide_core.chs=0.0:980,16,32 auto nousb console=ttyS0,9600 bigphysarea=65536 ide1=noprobe no-hlt


If you want to run multiple ASA's configure the options accordingly e.g.
Qemu options : -vnc :2 none -vga none -icount auto -hdachs 980,16,32 -cpu coreduo -nographic

Cisco config highlighting with Kate


Syntax highlight Engine Kate can be used to install more plugins for syntax highlighting


http://search.cpan.org/dist/Syntax-Highlight-Engine-Kate/

sudo apt-get install libsyntax-highlight-engine-kate-perl




Postgres 9 how to drop a database that is in-use





PostgreSQL's statistics collector is a subsystem that supports collection and reporting of information about server activity

Sample below to identify the procid for database cmdbuild:

postgres=# select * from pg_stat_activity where datname='cmdbuild';

datid datname procpid usesysid
44867 cmdbuild 2467 16384
44867 cmdbuild 2468 16384
(2 rows)

pg_cancel_backend and pg_terminate_backend send signals (SIGINT or SIGTERM respectively) to backend processes identified by process ID. 

postgres=# select pg_terminate_backend(procpid) from pg_stat_activity where datname='cmdbuild';
 pg_terminate_backend 
----------------------
 t
 t
(2 rows)

postgres=# DROP DATABASE cmdbuild;
DROP DATABASE