Arkiv

Arkiv för ‘Bash’ Kategori

Formattera en USB-pinne i Ubuntu

augusti 11th, 2012 Inga kommentarer

Kolla först vilken enhetsnamn pinnen har. Starta ett terminalfönster och skriv:

sudo fdisk -l

eller

mount

Sedan när du kollat namnet måste du avmontera pinnen. I mitt fall hette enheten för USB-pinnen /dev/sdb

umount /dev/sdb

Formattera nu pinnen. Jag väljer att formattera den med VFAT så den går att använda i Windows m.fl. operativsystem.

sudo mkfs.vfat /dev/sdb1

Om du vill döpa om namnet på pinnen i kommandoradsläge kan du installera mtools

sudo apt-get install mtools

Sedan kan det vara bra idé att hoppa över mtoolskontrollen av pinnen då man ibland får ett felmeddelande not a multiple of sectors per track (62)

echo mtools_skip_check=1 >> ~/.mtoolsrc

Döp sedan om USB-pinnen med följande kommando

sudo mlabel -i /dev/sdb1 ::namn

Klart!

Referenser:

http://www.cyberciti.biz/faq/howto-format-usb-pen-drive/

https://help.ubuntu.com/community/RenameUSBDrive

Categories: Bash, Linux Taggar:

Prepare Linux for source compile

augusti 11th, 2012 Inga kommentarer

1. Install packages to build the kernel modules

sudo apt-get install autoconf automake binutils make cpp gcc linux-headers-$(uname -r)

2. Find out where the kernel headers are (you may need this later)

ls -d /usr/src/linux-headers-$(uname -r)*/include

i.e. /usr/src/linux-headers-2.6.31-14-generic-pae/include

i.e. /lib/modules/2.6.31-14-generic-pae/build/include

3. Get the kernel source

sudo apt-get build-dep linux-image-$(uname -r)

sudo apt-get source linux-image-$(uname -r)

Categories: Bash, Linux, Programmering, Ubuntu Taggar:

DNS-323 SSH

augusti 11th, 2012 Inga kommentarer

För att lägga till SSH stöd i DNS-323:

http://www.bergek.com/2008/11/13/dlink-dns-323-part-3-fonz-fun_plug/

För att lägga in ett RSYNC jobb via CRON:

http://wiki.dns323.info/howto:backup

DNS323 + Duplicity = Encrypted Offsite Backup BLISS!:

http://www.drak0.com/2008/06/09/dns323-duplicity-encrypted-offsite-backup-bliss/

Modding Cron on the D-Link DNS-323 using funplug-0.3:

http://techblog357.blogspot.com/2007/08/modding-cron-on-d-link-dns-323-using.html

Modding ’crontab’ on Fujitsu Q700:

vi /etc/config/crontab

crontab /etc/config/crontab

Categories: Bash, Linux Taggar:

Move your Ubuntu/Debian installation to another computer

augusti 11th, 2012 Inga kommentarer

To move your Ubuntu/Debian installation to another computer:

1. Start a terminal window on your old computer

2. ’dpkg –get-selections > ~/instsoft.log’

3. Copy all files from your home folder to an external USB-drive

. (if you use Nautilus instead, remember to press CTRL+H to get all hidden files)

On the new computer:

1. Install the new computer with the same Linux version as the old one

2. Enter the folder containing your home folder copy (from step 3 above)

3. Start a terminal window

4. ’sudo apt-get install dselect’

5. ’sudo dpkg –set-selections < instsoft.log’

6. ’sudo dselect’

7. Select ’i’ and press Enter to start the software installation

. (internet access required)

ALT METHOD

To copy the entire disk to another disk (with partitions already prepared):

1. Mount the destination disk: sudo mkdir /mnt/extusb && mount -t ntfs-3g /dev/sda2/mnt/extusb

2. Copy all files: sudo cp -rpx / /mnt/extusb

3. Install Grub2 on the new disk

sudo mount /dev/sda2 /mnt

sudo mount –bind /dev /mnt/dev

sudo chroot /mnt

grub-install –recheck /dev/sda

dpkg-reconfigure linux-image-`uname -r`

Categories: Bash, Linux Taggar:

Check which Linux version

augusti 11th, 2012 Inga kommentarer

uname -a

cat /etc/lsb-release (shows Ubuntu version)

cat /proc/version

cat /proc/cpuinfo

cat /etc/issue

Categories: Bash, Linux Taggar:

How to figure out which process is listening on a specific port

augusti 11th, 2012 Inga kommentarer

This website explained it:

http://analysisandreview.com/troubleshooting/what-process-is-listening-on-a-port/

Let’s say we want to find our what process is tied to port 53.

First, use the following command to find if the port is is use or not

netstat -an | grep 53

#Then, use the following command to find which process is using the port

fuser -n tcp 53

This will return something like ’53/tcp: 5006′.

it shows pid.

After that, we can find the full process information.

ps -ef | grep 9113

If you know shell you can use the below in a shell script to put all these step together

#!/bin/sh
status=`netstat -an |grep $1`
if [ "$status" == "" ]; then
echo “port $1 is free”
exit
fi
ps -ef |grep `fuser -n tcp $1`

Or if you’re running linux download lsof

lsof -i :53

or

lsof -i :1226

Or you and use grep

lsof | grep [process name]
Categories: Bash, Linux Taggar:

Download gscan2pdf source and run

maj 9th, 2012 Inga kommentarer

THIS IS ONLY A DRAFT!!!

http://gscan2pdf.sourceforge.net/

Ladda ner koden:

cd ~/code
git clone git://gscan2pdf.git.sourceforge.net/gitroot/gscan2pdf/gscan2pdf

Skapa en länk så Perl hittar filerna:

sudo mkdir /usr/local/lib/perl
cd /usr/local/lib/perl
sudo ln -s /home/holm/code/gscan2pdf/lib 5.12.4

Starta programmet:

/home/holm/code/gscan2pdf/bin/gscan2pdf

// Tobias 2012-01-01

_____________________________________________________________

Install gscan2pdf from Ubuntu repositories to get most of the dependencies:

$ sudo apt-get install gscan2pdf git libsane-dev libcanberra-gtk-module

You might get the following packages when installing gscan2pdf:

Följande NYA paket kommer att installeras:
cuneiform cuneiform-common gocr gscan2pdf libconfig-general-perl libcuneiform0 libextutils-depends-perl libextutils-pkgconfig-perl libfont-ttf-perl libgoo-canvas-perl libgtk2-ex-podviewer-perl libgtk2-ex-simple-list-perl libgtk2-imageview-perl libgtkimageview0 libio-stringy-perl libjpeg-progs libjpeg-turbo-progs libleptonica liblog-log4perl-perl libpdf-api2-perl libproc-processtable-perl libreadonly-perl libset-intspan-perl libtesseract3 libtiff-tools libwebp2 perlmagick tesseract-ocr tesseract-ocr-eng tesseract-ocr-equ tesseract-ocr-osd

Download the source via git:

$ git clone git://gscan2pdf.git.sourceforge.net/gitroot/gscan2pdf/gscan2pdf

Enter the directory. If you try to run it you can get this error:

$ bin/gscan2pdf
 Can't locate Gscan2pdf/Document.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.12.4 /usr/local/share/perl/5.12.4 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.12 /usr/share/perl/5.12 /usr/local/lib/site_perl .) at bin/gscan2pdf line 121.                                      
 BEGIN failed--compilation aborted at bin/gscan2pdf line 121.

This is because the Perl script can’t find some libraries. To solve it, add the following at the top of bin/gscan2pdf:

# ADDED BY TOBIAS HOLM 2012-05-12 (TO FIND LIBS)
use lib "/home/holm/code/gscan2pdf/lib/";

This is another problem you can bump into:

$ bin/gscan2pdf
 Sane version 0.05 required--this is only version 0.03 at /etc/perl/Gscan2pdf/Scanner/Options.pm line 7.
 BEGIN failed--compilation aborted at /etc/perl/Gscan2pdf/Scanner/Options.pm line 7.
 Compilation failed in require at /etc/perl/Gscan2pdf/Document.pm line 7.
 BEGIN failed--compilation aborted at /etc/perl/Gscan2pdf/Document.pm line 7.
 Compilation failed in require at bin/gscan2pdf line 121.
 BEGIN failed--compilation aborted at bin/gscan2pdf line 121.

To fix it, download Sane version 0.05: https://metacpan.org/module/Sane

Enter the folder where you downloaded the files and try to install Sane:

$ perl Makefile.PL
 Perhaps you should add the directory containing `sane-backends.pc'
 to the PKG_CONFIG_PATH environment variable
 No package 'sane-backends' found at Makefile.PL line 21
 Writing Makefile for Sane
 Writing MYMETA.yml

Ops! Install sane-backends components:

$ sudo apt-get install libsane-dev

Now compile Sane:

$ perl Makefile.PL
$ make
$ make test
$ sudo make install

Enter gscan2pdf folder and run the program:

$ cd ../gscan2pdf
$ bin/gscan2pdf

This is another error:

$ bin/gscan2pdf 
Bareword "Gscan2pdf::_cancel_process" not allowed while "strict subs" in use at /etc/perl/Gscan2pdf/Document.pm line 595.
Compilation failed in require at bin/gscan2pdf line 54.
BEGIN failed--compilation aborted at bin/gscan2pdf line 54.

Fix it by manually cleaning up a previous installation of Gscan2pdf.

sudo apt-get remove gscan2pdf
sudo rm -rf /etc/perl/Gscan2pdf
Categories: Bash, Linux, Ubuntu Taggar:

Backup a MySQL database

mars 15th, 2012 Inga kommentarer

– if you have root access you can do mysql dump.

– if you have filesystem access you may stop mysql / flush tables with read lock and then copy data files.

– dump each of the db one by one!! may be a shellscript will do the job! You may directly redirect it to target db if it’s accesible:

mysqldump -uUSER -pPASS –databases DB1 | mysql -uUSER -pPASS -hREMOTEHOST/IP

To dump all the databases you issue:

mysqldump -uUSER -pPASS –all-databases > dumpfile.sql

and then issue:

mysql -uUSER -pPASS < dumpfile.sql

Categories: Bash, Linux, Programmering Taggar:

Install Adobe Flash in x64 Linux

mars 13th, 2012 Inga kommentarer

Download and unpack .tar from Adobe with Flash 64 bit.

In Kubuntu 12.04 with Firefox 17.0.1:

$ sudo cp libflashplayer.so /usr/lib/firefox-addons/plugins

In Ubuntu?

NOT TESTED YET!

$ sudo cp /home/user/Downloads/plug.so /etc/alternatives/mozilla-flashplugin

$ sudo ln -s /usr/lib/mozilla/plugins/ /etc/alternatives/mozilla-flashplugin

$ ls /usr/lib/mozilla/plugins/ -l

lrwxrwxrwx 1 root root 37 2012-03-12 11:49 flashplugin-alternative.so -> /etc/alternatives/mozilla-flashplugin

Categories: Bash, Linux Taggar:

Remove åäö from file names and folders

maj 30th, 2011 Inga kommentarer
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os

def syntax(item):
# åäö->aao
nn=item.replace('å','a').replace('ä','a').replace('ö','o')
nn=nn.replace('Å','A').replace('Ä','A').replace('Ö','O')
nn=nn.replace('ü','u').replace('Ü','U')
nn=nn.replace('é','e').replace('É','E')

#special chars -> underscore
#    for uscore in ("'",'`',"'",'^','"','¨','(',')','[',']','=',
#                   ',',':',';','*','!','@','£','#','¤','$','%','&','{','}'):
#      nn=nn.replace(uscore,'_')

return nn

for root,dirs,files in os.walk('./',topdown=False):
for name in files: # First change name of the files
newname=os.path.join(root,syntax(name))
name=os.path.join(root,name)
os.rename(name,newname)

for name in dirs: # Then change name of the folders
newname=os.path.join(root,syntax(name))
name=os.path.join(root,name)
os.rename(name,newname)
Categories: Bash, Linux, Programmering Taggar: