Langsung ke konten utama

Postingan

Remote Port Forwarding

$ ssh -nNT -R 4000:localhost:3000 user@server.com The above command sets up an ssh tunnel between your machine and the server, and forwards all traffic from localhost:3000 (on your machine) to localhost:4000 (in the context of the server). So now you can connect to the locally running service on port 3000 on the server on port 4000. This trick is very useful because it allows you to be able to expose a locally running service through your server to others on the internet without having to deploy it / setup on the server.

Can't Use apt i.e. /boot is 100% full

1. Get the list of kernel images Get the list of kernel images and determine what you can do without. This command will show installed kernels except the currently running one $ sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r` You will get the list of images somethign like below: linux-image-3.19.0-25-generic linux-image-3.19.0-56-generic linux-image-3.19.0-58-generic linux-image-3.19.0-59-generic linux-image-3.19.0-61-generic linux-image-3.19.0-65-generic linux-image-extra-3.19.0-25-generic linux-image-extra-3.19.0-56-generic linux-image-extra-3.19.0-58-generic linux-image-extra-3.19.0-59-generic linux-image-extra-3.19.0-61-generic 2. Prepare Delete Craft a command to delete all files in /boot for kernels that don't matter to you using brace expansion to keep you sane. Remember to exclude the current and two newest kernel images. From above Example, it's sudo rm -rf /boot/*-3.19.0-{25,56,58,59,61,65}-*

export mysql to csv with command line

First, I can give you the answer for ONE table: The trouble with all these INTO OUTFILE or --tab=tmpfile (and -T/path/to/directory) answers is that it requires running mysqldump on the same server as the MySQL server, and having those access rights. My solution was simply to use mysql (NOT mysqldump) with the -B parameter, inline the SELECT statement with -e, then massage the ASCII output with sed, and wind up with CSV including a header field row: Example: mysql -B -u root -p dbname -e "SELECT * FROM query;" | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > test.csv output: "id","login","password","folder","email" "8","mariana","xxxxxxxxxx","mariana","" "3","squaredesign","xxxxxxxxxxxxxxxxx","squaredesign","mkobylecki@squaredesign.com" "4","miedziak",

[sshtunnel.py:notify_exception_error:233]: Traceback (most recent call last) | Use module Crypto.Signature.pkcs1_15 instead

Recently I started getting the following error in a script that never had any problems in the past: NotImplementedError: Use module Crypto.Signature.pkcs1_15 instead There wasn’t much information related to this error in regards to Paramiko. Eventually I was able to “fix” it by running: sudo -H pip uninstall paramiko sudo -H pip uninstall pycrypto sudo -H pip install paramiko done

How to recover deleted file held open by Apache

If a file has been deleted but is still open, that means the file still exists in the filesystem (it has an inode) but has a hard link count of 0. Since there is no link to the file, you cannot open it by name. There is no facility to open a file by inode either. Linux exposes open files through special symbolic links under  /proc . These links are called  /proc/12345/fd/42  where 12345 is the  PID  of a process and 42 is the number of a file descriptor in that process. A program running as the same user as that process can access the file (the read/write/execute permissions are the same you had as when the file was deleted). The name under which the file was opened is still visible in the target of the symbolic link: if the file was  /var/log/apache/foo.log , then the target of the link is  /var/log/apache/foo.log (deleted) . Thus you can recover the content of an open deleted file given the  PID  of a process that has it open and the descriptor that it's opened on like thi