Skip to content

Instantly share code, notes, and snippets.

@refraction-ray
Last active February 11, 2018 12:19
Show Gist options
  • Save refraction-ray/be904f07dcb7a6b34dbc73e96fad6b91 to your computer and use it in GitHub Desktop.
Save refraction-ray/be904f07dcb7a6b34dbc73e96fad6b91 to your computer and use it in GitHub Desktop.
demo on jupyter notebook running shell commands in Joinquant
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## linux command demo\n",
"This file is a demo on how many terminal commands can be conducted in jupyter notebook of joinquant and how much info you can acquire on the backend.\n",
"IMHO, the permission is somewhat loose here and may potentially increase the risk.\n",
"As a quant finace platform, they shouldn't expose so much command to their users."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 16 Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz\r\n"
]
}
],
"source": [
"!cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[31mDEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.\u001b[0m\n",
"pyecharts (0.2.7)\n"
]
}
],
"source": [
"!pip list|grep echarts"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"127.0.0.1\tlocalhost\r\n",
"::1\tlocalhost ip6-localhost ip6-loopback\r\n",
"fe00::0\tip6-localnet\r\n",
"ff00::0\tip6-mcastprefix\r\n",
"ff02::1\tip6-allnodes\r\n",
"ff02::2\tip6-allrouters\r\n"
]
}
],
"source": [
"!cat /etc/hosts"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Debian GNU/Linux 8 \\n \\l\r\n",
"\r\n"
]
}
],
"source": [
"!cat /etc/issue"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PING google.com (172.217.160.78): 56 data bytes\n",
"--- google.com ping statistics ---\n",
"2 packets transmitted, 0 packets received, 100% packet loss\n"
]
}
],
"source": [
"!ping -c 2 google.com"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MemTotal: 65964932 kB\r\n"
]
}
],
"source": [
"!cat /proc/meminfo |grep MemTotal"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Filesystem Size Used Avail Use% Mounted on\r\n",
"overlay 99G 59G 36G 63% /\r\n",
"tmpfs 64M 0 64M 0% /dev\r\n",
"tmpfs 32G 0 32G 0% /sys/fs/cgroup\r\n",
"/dev/vda1 40G 16G 22G 42% /etc/joinquant_user\r\n",
"1d1d2488ae-gmq3.cn-beijing.nas.aliyuncs.com:/586/58690411326 1.0P 1.1T 1023T 1% /home/jquser\r\n",
"/dev/vdb1 99G 59G 36G 63% /etc/hosts\r\n",
"shm 64M 0 64M 0% /dev/shm\r\n",
"none 32G 1.2G 31G 4% /dev/shm/daydata\r\n",
"tmpfs 32G 0 32G 0% /proc/scsi\r\n",
"tmpfs 32G 0 32G 0% /sys/firmware\r\n"
]
}
],
"source": [
"!df -h"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"matplotlib\r\n"
]
}
],
"source": [
"!ls .config"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"apt 1.0.9.8.1 for amd64 compiled on Jun 10 2015 09:42:07\r\n",
"Usage: apt [options] command\r\n",
"\r\n",
"CLI for apt.\r\n",
"Basic commands: \r\n",
" list - list packages based on package names\r\n",
" search - search in package descriptions\r\n",
" show - show package details\r\n",
"\r\n",
" update - update list of available packages\r\n",
"\r\n",
" install - install packages\r\n",
" remove - remove packages\r\n",
"\r\n",
" upgrade - upgrade the system by installing/upgrading packages\r\n",
" full-upgrade - upgrade the system by removing/installing/upgrading packages\r\n",
"\r\n",
" edit-sources - edit the source information file\r\n"
]
}
],
"source": [
"!apt -h"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Python 3.6.3 :: Anaconda, Inc.\r\n"
]
}
],
"source": [
"!python3 -V"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/opt/conda/envs/python3new/bin/python\r\n"
]
}
],
"source": [
"!which python"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\r\n",
" link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\r\n",
" inet 127.0.0.1/8 scope host lo\r\n",
" valid_lft forever preferred_lft forever\r\n",
" inet 10.255.72.189/32 brd 10.255.72.189 scope global lo\r\n",
" valid_lft forever preferred_lft forever\r\n",
"3542: eth0@if3543: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default \r\n",
" link/ether 02:42:0a:ff:48:be brd ff:ff:ff:ff:ff:ff\r\n",
" inet 10.255.72.190/16 brd 10.255.255.255 scope global eth0\r\n",
" valid_lft forever preferred_lft forever\r\n",
"3544: eth1@if3545: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default \r\n",
" link/ether 02:42:c0:a8:00:0c brd ff:ff:ff:ff:ff:ff\r\n",
" inet 192.168.0.12/20 brd 192.168.15.255 scope global eth1\r\n",
" valid_lft forever preferred_lft forever\r\n"
]
}
],
"source": [
"!ip addr"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)\r\n",
"E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?\r\n"
]
}
],
"source": [
"!apt install hping3"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2018-02-11 19:56:46-- http://baidu.com/\n",
"Resolving baidu.com (baidu.com)... 111.13.101.208, 220.181.57.216, 123.125.114.144\n",
"Connecting to baidu.com (baidu.com)|111.13.101.208|:80... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 81 [text/html]\n",
"Saving to: ‘index.html’\n",
"\n",
"index.html 100%[=====================>] 81 --.-KB/s in 0s \n",
"\n",
"2018-02-11 19:56:46 (7.15 MB/s) - ‘index.html’ saved [81/81]\n",
"\n"
]
}
],
"source": [
"!wget baidu.com"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"bin dev home lib64\tmnt proc run\t srv tmp var\r\n",
"boot etc lib\t media\topt root sbin sys usr\r\n"
]
}
],
"source": [
"!ls /"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" [ - ] bootlogs\n",
" [ - ] bootmisc.sh\n",
" [ - ] checkfs.sh\n",
" [ - ] checkroot-bootclean.sh\n",
" [ - ] checkroot.sh\n",
" [ - ] hostname.sh\n",
" [ ? ] hwclock.sh\n",
" [ - ] killprocs\n",
" [ - ] motd\n",
" [ - ] mountall-bootclean.sh\n",
" [ - ] mountall.sh\n",
" [ - ] mountdevsubfs.sh\n",
" [ - ] mountkernfs.sh\n",
" [ - ] mountnfs-bootclean.sh\n",
" [ - ] mountnfs.sh\n",
" [ - ] procps\n",
" [ - ] rc.local\n",
" [ - ] rmnologin\n",
" [ - ] sendsigs\n",
" [ - ] sudo\n",
" [ + ] udev\n",
" [ ? ] udev-finish\n",
" [ - ] umountfs\n",
" [ - ] umountnfs.sh\n",
" [ - ] umountroot\n",
" [ - ] urandom\n",
" [ - ] x11-common\n"
]
}
],
"source": [
"!service --status-all"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"jquser\r\n"
]
}
],
"source": [
"!whoami"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/jquser\r\n"
]
}
],
"source": [
"!pwd"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"root 1 0.0 0.0 46996 3476 ? Ss 08:10 0:00 sudo -E PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/conda/bin:/opt/jdk1.8.0_92/bin -u jquser jupyterhub-singleuser --port=8888 --ip=0.0.0.0 --user=58690411326 --cookie-name=jupyter-hub-token-58690411326 --base-url=/user/58690411326 --hub-prefix=/hub/ --hub-api-url=http://10.45.136.71:8081/hub/api --notebook-dir=/home/jquser --static-url-prefix='https://cdn.joinquant.com/research/jupyter/' --nbextensions-url='https://cdn.joinquant.com/research/jupyter/nbextensions/'\r\n",
"jquser 21 0.2 0.6 862520 415756 ? Sl 08:10 1:29 python3 /usr/local/bin/jupyterhub-singleuser --port=8888 --ip=0.0.0.0 --user=58690411326 --cookie-name=jupyter-hub-token-58690411326 --base-url=/user/58690411326 --hub-prefix=/hub/ --hub-api-url=http://10.45.136.71:8081/hub/api --notebook-dir=/home/jquser --static-url-prefix='https://cdn.joinquant.com/research/jupyter/' --nbextensions-url='https://cdn.joinquant.com/research/jupyter/nbextensions/'\r\n",
"jquser 355 0.0 0.1 1074788 119456 ? Sl 19:22 0:02 /opt/conda/envs/python3new/bin/python -m ipykernel_launcher -f /home/jquser/.local/share/jupyter/runtime/kernel-054a4dfe-7596-4092-ab24-ba672f723b4e.json\r\n",
"jquser 404 0.2 0.1 1076060 121616 ? Sl 19:36 0:04 /opt/conda/envs/python3new/bin/python -m ipykernel_launcher -f /home/jquser/.local/share/jupyter/runtime/kernel-f2395ac1-8c69-4460-bc3f-c73b1cb8bf8b.json\r\n",
"jquser 795 0.0 0.0 4328 720 pts/0 Ss+ 20:09 0:00 /bin/sh -c ps -aux|grep jupyter\r\n",
"jquser 797 0.0 0.0 12808 968 pts/0 S+ 20:09 0:00 grep jupyter\r\n"
]
}
],
"source": [
"!ps -aux|grep jupyter"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"awk is /usr/bin/awk\r\n",
"sed is /bin/sed\r\n",
"tee is /usr/bin/tee\r\n",
"perl is /usr/bin/perl\r\n",
"head is /usr/bin/head\r\n",
"gcc is /usr/bin/gcc\r\n",
"as is /usr/bin/as\r\n",
"bash is /bin/bash\r\n",
"rm is /bin/rm\r\n",
"sudo is /usr/bin/sudo\r\n",
"mkdir is /bin/mkdir\r\n",
"mount is /bin/mount\r\n"
]
}
],
"source": [
"!type awk sed tee perl head gcc as bash rm sudo mkdir mount"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (PacVer 2.0)",
"language": "python",
"name": "python3new"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment