Entries tagged Linux

Commandline: Which programs are using network connection

Posted on 29. August 2017 Comments

lsof -P -i -n | cut -f 1 -d " " | uniq

lsof – list open files
-P list port numbers instead of service names
-i list all network files
-n IP addresses instead of host names

cut – cut output
-f specifies fields, separated in the input by the field delimiter character (-d)
-d delimiter

uniq – filters out repeated lines

Fix shipping providers for FBA orders in Plentymarkets

Posted on 27. Februar 2017 Comments

The popular ERP Plentymarkes let’s you send your orders via the Fulfillment by Amazon program to your customers. Amazon is just used as a logistics partner, the order doesn’t have to come via Amazon. It could e.g. be a Rakuten or eBay order. The problem that Plentymarkets didn’t address at all and is discussed in the private forums, is that Amazon chooses whatever shipping company they seem fit.

Every order has a standard shipping provider and with it comes a URL for tracking the package. Most of the vendors would implement an event procedure („Ereignisaktion“) that sends an email to the customer containing the order and the TrackingID as soon as it’s shipped. The TrackingIDs are directly imported from Amazon. Unfortunately Plentymarkets does not change the shipping provider in case it’s not the default one (which is often the case). So the customer gets wrong information.

In one of last last blogposts I introduced a PHP package to check which shipping provider a TrackingID belongs to by either scraping their website or using a regular expression and filtering for common patterns. In this blog post I want to explain how to use it to fix those orders. You will need a webserver with PHP and MySQL and a little knowledge of programming and Linux.

You can find some simplified code examples on GitHub soon.

  1. Take your FBA orders out of the event procedures that sends the email to the customers, filter e.g. via WarehouseID
  2. Instead, use an event procedure to mark those orders with a flag, e.g. a star (ID 2)
  3. Create a DynamicExport of the type OrderComplete. Filter for your Sent Status (usually 7) and WarehouseID of FBA orders. Include these fields:
    1. OrderID
    2. OrderPackageNo
    3. OrderParcelServiceID
    4. OrderParcelServicePresetID
    5. OrderLastUpdateTimestamp
  4. Implement the SOAP Call GetDynamicExport (will be replaced by REST via Plugin mid-2017)
  5. Write a Cronjob that calls the GetDynamicExport script with the FormatID of the DynamicExport from #2
  6. Create a database table called ‚pm_shipping_providers_check‚ with the fields from #2
  7. Write a script that imports the CSV you downloaded with the GetDynamicExport call into your MySQL database
  8. Create another DynamicExport, this time of the type Order. Include these fields:
    1. OrderID (Synchronisation)
    2. ParcelServiceID (Import)
    3. ParcelServicePresetID (Import)
    4. PackageNo (Import)
  9. Create a table with these fields called ‚pm_shipping_providers_correction
  10. Create a script, that uses the shipping-service-provider-check library to check the every PackageNo in ‚pm_shipping_providers_check‘ and – if the provider is different from the default one – writes it into ‚pm_shipping_providers_correction‘
  11. Implement the SOAP Call SetDynamicImport (see #3)
  12. Write a script that exports the table ‚pm_shipping_providers_correction‘ into a (semicolon seperated) CSV.
  13. Create a cronjob that uploads the file regularly
  14. Create an event procedure on the event PackageNo that sends out emails, but only for the previously flagged orders

MySQL Workbench Error: line contains NULL byte

Posted on 21. April 2016 Comments

When importing CSV (or other) files into the database, scripts (especially PHP or C-related languages), will stop if there is – for whatever reason – a NULL byte in your file because it signals end of file/string, see Null bytes related issues.

So when importing a file like that with MySQL Workbench you will get this error:

line contains NULL byte

You can solve this by using the commandline tool tr (from coreutils):

tr < file-with-nulls -d '\000' > file-without-nulls

To check if there are any null bytes in your file, use the python IDE and type in:

open('filename.ext').read().index('\0')

Thanks to Pointy from Stackoverflow

Simple wget crawler for list of files

Posted on 6. August 2015 Comments

This script could be helpful to download a set of files from a webserver, that you don’t have (S)FTP access to. The input file consists of a list of filenames, one name each line.


#!/bin/bash
file=$1
WEBSERVER="http://webserver.tld/folder/"
while IFS= read -r line; do
FULLURL="$WEBSERVER$line"
wget -nc -R --spider $FULLURL
done < "$file"

At first, the first command line argument is saved into the variable file. Then the Webserver address is saved to the WEBSERVER variable. IFS stands for Internal Field Separator. It’s used to read line by line through the file in the while loop that ends in the last line. Inside of the loop, the read line is concatenated with the webserver address into FULLURL. Then, wget is used with the parameters -nc for checking if the file is not already present in the current folder, -R for downloading and –spider for checking the existence on the webserver.

You can find the script on GitHub.

MySQL Verbindungen in C++ mit mysqlpp

Posted on 6. November 2013 Comments

MySQL Server und Header installieren:

sudo apt-get install mysql-server  libmysqlclient-dev libmysql++-dev

In Eclipse C++-Projekt anlegen, Rechtsklick auf das Projekt:

Properties>C/C++-Build>Settings>Tool Settings>GCC C++ Compiler>Includes
Dort die Pfade /usr/include/mysql und /usr/include/mysql++ als Include paths eintragen.

cpp_mysql1

 

Weiter unten unter GCC C++ Linker>Libraries>Libraries „mysqlpp“ eintragen und unter Library search paths ebenfalls /usr/include/mysql und /usr/include/mysql++.

cpp_mysql2

 

Unter Miscellaneous dann noch bei Other objects die Datei /usr/lib/x86_64-linux-gnu/libmysqlclient.so angeben:

cpp_mysql3

 

Beispieldatei: mysqlpptest.cpp

 

Credits: C++ with a shot of MySQL on Ubuntu 10.10

ActiveMQ mit C++ und Eclipse

Posted on 6. November 2013 Comments

Vorraussetzungen

Vorbereitung

sudo apt-get update && apt-get upgrade && apt-get install build-essential autoconf libaprutil1-dev libapr1-dev

cd ~/Development

wget http://mirror.softaculous.com/apache/activemq/activemq-cpp/source/activemq-cpp-library-3.4.5-src.tar.gz

tar -xvzf activemq-cpp-library-3.4.5-src.tar.gz

cd activemq-cpp-library-3.4.5-src

./configure

make

ActiveMQ-CPP

Dann mit sudo make install auf dem lokalen Rechner installieren. Damit befinden sich dann die .so-Dateien in /usr/local/lib.

In Eclipse

  1. Neu -> C++ Project
  2. Rechtsklick Projekt -> Properties
  3. C/C++ -> Build -> Settings -> GCC C++ Compiler -> Includes
  4. Unter include paths Pfad von ActiveMQ-CPP: /home/user/workspace/activemq-cpp-3.4.5/activemq-cpp/src/main hinzufügen oder anpassen
  5. Dort auch Pfad von APR hinzufügen: /usr/include/apr-1.0
  6. Die beiden auch beim Linker als library search path hinzufügen oder anpassen
  7. Als shared Object beim Linker /usr/local/lib/libactivemq-cpp.so hinzufügen

Beispiele

Die Projekte unter activemq-cpp-3.4.5/activemy-cpp/src/examples lassen sich jetzt kompilieren, allerdings kommt beim starten folgende Fehlermeldung:

./activeMQProducer: error while loading shared libraries: libactivemq-cpp.so.14: 
cannot open shared object file: No such file or directory

Der Fehler lässt sich mit folgendem Befehl beheben(credit):

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

Diesen Artikel hatte ich bereits vor einem Jahr(Ende 2012) geschrieben. Vielleicht gibt es neue Versionen der benutzen Software.

SQLDeveloper with Ubuntu 12.04, alien and the .rpm-file

Posted on 30. September 2013 Comments

There are a couple of tutorials[1] of how to install Oracles SQLDeveloper and they all say to install the sqldeveloper-XXX-no-jre.zip, in this case sqldeveloper-3.2.20.09.87-no-jre.zip. I didn’t read it because my first idea was the following and it also worked: It’s possible to download the .rpm-file and convert it with alien. You might have to install it with

sudo apt-get install alien

then

alien sqldeveloper-3.2.20.09.87-1.noarch.rpm
dpkg -i sqldeveloper_3.2.20.09.87-2_all.deb

You can then start the sqldeveloper. It will ask you for the Java Path which is usually /usr/lib/jvm/java-6-openjdk and give you some kind of error, which didn’t seem to have any impact.

repat@laptop:~$ sqldeveloper
Oracle SQL Developer
Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
Type the full pathname of a J2SE installation (or Ctrl-C to quit), the path will be stored in ~/.sqldeveloper/jdk
/usr/lib/jvm/java-6-openjdk
/opt/sqldeveloper/sqldeveloper/bin/../../ide/bin/launcher.sh: Zeile 455: /home/repat/.sqldeveloper/jdk: Datei oder Verzeichnis nicht gefunden

[1] e.g. Oracle Forum, Linux Sagas, Software in a bottle

Grub installieren ohne Linux mit Wechsel der Startreihenfolge unter Windows

Posted on 9. August 2013 Comments

GRUB ist ein Bootloader, der häufig für Linuxsysteme zum Einsatz kommt. Besonders praktisch ist er für Dual-Boot Systeme, wenn man z.B. noch die Windows Installation für ein paar Programme braucht und sonst auf Linux arbeitet oder auch andersherum, kann man beim Start des Computers auswählen, welches System starten soll. Oder unterschiedliche Linux Distributionen. Oder oder oder…halt auch 2 Windows Installationen. Dafür braucht es allerdings kein Linux, da man GRUB natürlich auch ohne ein Linux läuft.

In diesem Beispiel habe ich erst Windows XP und Windows 7 installiert. Wie das geht, ohne dass die beiden sich in die Quere kommen, habe ich in einem anderen Blog-Eintrag geschrieben. Diese Anleitung geht davon aus, dass XP und 7 bereits installiert sind.

1. Linux Live CD downloaden.

Ich habe Ubuntu genommen, die Live-CD bekommt man auf der Website. Einfach starten und den Live Modus auswählen.

 

2. GRUB 2 deinstallieren

Für dieses Beispiel werde ich GRUB 1/GRUB Legacy verwenden. Es basiert auf einer simplen Textdatei, die übersichtlich und gut editierbar ist.

sudo apt-get remove grub*

3. GRUB 1 installieren

sudo apt-get install grub

4. ext2 Partition erstellen

gparted aus dem Startmenü wählen. Bei der Installation von Windows XP und Windows 7 habe ich so viel Platz gelassen, dass man hinter den beiden Partitionen noch eine z.B. 256MB große Partition erstellen kann, aufgrund der verfügbaren Windows Tools zum Lesen bzw. Schreiben von Linux Partionen nehme ich hier ext2. Ist die Partition erstellt, gebe ich dieser Partition das boot-flag.

 

5. GRUB auf dieser Partition installieren

Erstmal die neu erstellte Partition mounten. Nach Windows XP(/dev/sda1) und Windows 7(/dev/sda2) ist das hier logischerweise /dev/sda3. Gemountet wird sie hier z.B. nach /mnt.

sudo mount /dev/sda3 /mnt

Jetzt kommt die eigentliche Installation, die GRUB in den MBR schreibt und damit Windows 7 dort überschreibt. Das root-directory flag gibt an, wohin GRUB die Dateien schiebt. /dev/sda ist das Gerät(!) auf dem der MBR geschrieben wird, hier also nicht die Partition angeben!

sudo grub-install --root-directory=/mnt /dev/sda

Fertig 🙂 Jetzt muss man nur noch die Datei /mnt/boot/grub/menu.lst erstellen. Man kann sich eine default Variante erstellen mit folgendem Befehl

sudo update-grub

Ihr findet dann in /boot/grub/menu.lst eine Vorlage, die man erstmal 1:1 kopieren kann in /mnt/boot/grub/menu.lst.

Um Windows XP und Windows 7 nebeneinander zu booten muss man wie im letzten Blog Artikel erklärt die hidden Flags setzen. Für Sicherungen, bei denen man ganze Festplatten sichert ist es aber nötig die hidden flags beide zu entfernen. Hierfür habe ich mir einen Dummy Eintrag gebastelt, der an dritter Stelle steht. Den Kernel gibt es natürlich auf meiner Installation nicht und sollte man versuchen diesen Eintrag zu starten gibt er eine Fehlermeldung aus. Beim Start von Windows XP muss man jeweils Windows 7 ausblenden und anders herum. Meine menu.lst sieht(im relevanten Teil)  so aus:

title        WindowsXP
hide        (hd0,1)
unhide        (hd0,0)
root        (hd0,0)
makeactive
savedefault
chainloader    +1

title        Windows7
hide        (hd0,0)
unhide        (hd0,1)
root        (hd0,1)
makeactive
savedefault
chainloader    +1

title        Dummy
unhide        (hd0,0)
unhide        (hd0,1)
root        (hd0,0)
kernel        /boot/memtest86+.bin

 

Natürlich gibt es hier auch die Möglichkeit neue Einträge im GRUB hinzuzufügen. Wenn man die User aussperren möchte, legt man also ein Passwort fest. Dies am besten nicht im Klartext; Grub bietet hier allerdings nur MD5 an.

Benutzt z.B. dieses Perl Skript von mir um euer Passwort lokal in einen MD5 Hash umzuwandeln.

Dann kommt einfach dieser Eintrag hinzu

password --md5 $1$MD5HASH

6. Wechsel zwischen Windows XP und Windows 7 als default Eintrag.

Für das Umschalten zwischen Windows Installationen habe ich 2 Batchdateien erstellt: bootwinxp.bat und bootwin7.bat. Beide befinden sich in C:\Windows\system32, also im PATH. Wie man ext2 zum Schreibenrechten mountet erfahrt ihr in meinem anderen Blog-Eintrag. Ich gehe einfach mal davon aus, dass die eben erstellte GRUB-Partition auf X:\ gemountet ist. Der Einfachheit halber mache ich dort keine komplizierten Textersetzungsbefehle sondern erstelle einfach eine menu.xp und eine menu.7 Datei auf dieser Partition. Diese enthalten entweder einen anderen Wert für default in menu.lst oder eine andere Reihenfolge, d.h. jeweils Windows XP oder Windows 7 steht zuerst in der Datei(default ist standardmässig auf 0). Diese beiden Dateien überschreiben dann mit

COPY X:\boot\grub\menu.xp X:\boot\grub\menu.lst

bzw.

COPY X:\boot\grub\menu.7 X:\boot\grub\menu.lst

in bootxp.bat bzw. boot7.bat einfach nur die aktuelle menu.lst und beim nächsten Bootvorgang wird dann das jeweilige Betriebsystem gebootet. Wenn man mehrere Rechner verwaltet, kann man diese Batch Datei z.B. auch über SSH aufrufen.