├── README.md └── Colab_RDP.ipynb /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Collab-Rdp 4 | 5 | ## RDP - or Remote Desktop Protocole helps you to connect to a Remote Desktop System and Control it just like any other normal Software.(similar to using using Ubuntu on Virtual Box) 6 | ## Google Collab provides you upto 12 hours of compute time. *There would be no restrtions on sites or applications* 7 | ## You can follow the steps given to connect to a collab system via Chrome Remote Desktop. 8 | 9 | 10 | ## To open the notebook Click on below button 11 | 12 | 13 | 14 | This notebook will be open 15 | 16 | ![image](https://user-images.githubusercontent.com/50911878/115740249-4313b700-a3ac-11eb-95f6-c0ffc1fb5ff7.png) 17 | 18 | ## Step - 1 Connection 19 | 20 | **In Right Corner Click on connect arrow** 21 | 22 | ![image](https://user-images.githubusercontent.com/50911878/115741913-cd104f80-a3ad-11eb-941d-64a8d5c98fcd.png) 23 | 24 | **After that you will see some options like** 25 | 26 | ![image](https://user-images.githubusercontent.com/50911878/115742562-67709300-a3ae-11eb-893d-198a454da4cf.png) 27 | 28 | **click on `connect to hosted runtime` which will allocate & connect to google cloud inctance** 29 | --------- 30 | 31 | > You can skip above step and dirctly click on run button of create user cell all the above procees will be done automatically 32 | 33 | ## Step - 1-a User Creation 34 | 35 | user and password are used for machine and will be needed if you lock the linux machine 36 | 37 | ![image](https://user-images.githubusercontent.com/50911878/115743896-b539cb00-a3af-11eb-92b7-1e82ab425f5e.png) 38 | 39 | After you click on run button you will get a warning dilog box click on run anyway 40 | 41 | ![image](https://user-images.githubusercontent.com/50911878/115744541-490b9700-a3b0-11eb-8ea0-a7163594f85b.png) 42 | 43 | now you will see user creation process will be started and after few seconds you will see a user is created successfully 44 | 45 | ![image](https://user-images.githubusercontent.com/50911878/115745108-c1725800-a3b0-11eb-934d-20c91f3cbca7.png) 46 | 47 | ## Step - 2 RDP conection using google remote desktop 48 | 49 | visit this link 50 | 51 | ![image](https://user-images.githubusercontent.com/50911878/115745857-74db4c80-a3b1-11eb-8993-d46254d82144.png) 52 | 53 | 54 | you will see install button in url tab before bookmark button 55 | click it to install in your desktop so that you do not have to open browser 56 | 57 | 58 | ![image](https://user-images.githubusercontent.com/50911878/115747446-e5cf3400-a3b2-11eb-9b82-bd11f5d0c908.png) 59 | 60 | 61 | 62 | now you will see a icon in desktop 63 | 64 | ![image](https://user-images.githubusercontent.com/50911878/115750697-1369ac80-a3b6-11eb-8abd-496ef5b9702f.png) 65 | 66 | **open that** 67 | 68 | you will see window like this 69 | 70 | ![image](https://user-images.githubusercontent.com/50911878/115750899-46ac3b80-a3b6-11eb-8508-b92b61aab9f4.png) 71 | 72 | 73 | ## Step 3 - Authorization 74 | 75 | click on begin button 76 | 77 | ![image](https://user-images.githubusercontent.com/50911878/115751173-8d9a3100-a3b6-11eb-830e-9fb29c04edb8.png) 78 | 79 | 80 | then click on next 81 | 82 | ![image](https://user-images.githubusercontent.com/50911878/115751414-cc2feb80-a3b6-11eb-8128-cb3e12327494.png) 83 | 84 | 85 | then click on authorise 86 | 87 | ![image](https://user-images.githubusercontent.com/50911878/115751587-f2ee2200-a3b6-11eb-979c-9deade2bc7bf.png) 88 | 89 | 90 | now google sign in dilog will pop up then select any one of account to authorise 91 | 92 | ![image](https://user-images.githubusercontent.com/50911878/115753047-5a58a180-a3b8-11eb-8f44-3262a83ed6ca.png) 93 | 94 | 95 | **choose any one of the account {next time you have to use same account}** 96 | 97 | after authentication some key will be genreted 98 | 99 | ![image](https://user-images.githubusercontent.com/50911878/115753256-9db31000-a3b8-11eb-8829-47d16ebd2308.png) 100 | 101 | you have to copy key of Debian Linux 102 | 103 | ![image](https://user-images.githubusercontent.com/50911878/115753348-bcb1a200-a3b8-11eb-8c58-b29dbd61dcd1.png) 104 | 105 | ## Step - 4 Configuration 106 | 107 | Paste this key to crp text field in notebook 108 | 109 | ![image](https://user-images.githubusercontent.com/50911878/115753588-fda9b680-a3b8-11eb-809a-9f1602d494ef.png) 110 | 111 | > **You Can change the `pin` if you want it will required in connecting with the inctance** 112 | 113 | After that click run button of RDP cell then it will install some tools 114 | 115 | ![image](https://user-images.githubusercontent.com/50911878/115758065-5b8bcd80-a3bc-11eb-836a-11e9cebf648b.png) 116 | 117 | 118 | ![image](https://user-images.githubusercontent.com/50911878/115756328-b8d34f00-a3bb-11eb-9342-e8a2122c61a7.png) 119 | 120 | after Installation completed then go to the google remote desktop 121 | 122 | 123 | ![image](https://user-images.githubusercontent.com/50911878/115753348-bcb1a200-a3b8-11eb-8c58-b29dbd61dcd1.png) 124 | 125 | 126 | **And click on `remote access`** 127 | 128 | ![image](https://user-images.githubusercontent.com/50911878/115759059-71e65900-a3bd-11eb-8210-e5266c75308d.png) 129 | 130 | after that you will see an online instance(remote device) 131 | 132 | ![image](https://user-images.githubusercontent.com/50911878/115759234-a6f2ab80-a3bd-11eb-9595-7ff6222f4eea.png) 133 | 134 | click on that you will see connecting 135 | 136 | ![image](https://user-images.githubusercontent.com/50911878/115759362-ca1d5b00-a3bd-11eb-9456-1dd225447ce4.png) 137 | 138 | after connecting copy the pin from the notebook in `RDP Cell` 139 | 140 | ![image](https://user-images.githubusercontent.com/50911878/115759583-0650bb80-a3be-11eb-9941-3a54c9e3fb69.png) 141 | 142 | and paste in the text field in google remote desktop 143 | 144 | ![image](https://user-images.githubusercontent.com/50911878/115759664-22545d00-a3be-11eb-87a8-b8d987acf7d8.png) 145 | 146 | then check the checkbox 147 | 148 | ![image](https://user-images.githubusercontent.com/50911878/115759854-59c30980-a3be-11eb-98fb-dae4dfdc4ade.png) 149 | 150 | and click on the arrow button 151 | 152 | ![image](https://user-images.githubusercontent.com/50911878/115759945-73fce780-a3be-11eb-823d-acd05fdd38c7.png) 153 | 154 | it will show connecting 155 | 156 | ![image](https://user-images.githubusercontent.com/50911878/115759999-8119d680-a3be-11eb-9f61-964f77c3cabb.png) 157 | 158 | after connectimg it will open the linux instance 159 | 160 | ![image](https://user-images.githubusercontent.com/50911878/115760162-a870a380-a3be-11eb-832e-29737aa712e5.png) 161 | 162 | click on `use default config` 163 | 164 | ![image](https://user-images.githubusercontent.com/50911878/115760252-c2aa8180-a3be-11eb-98a8-58991917bddd.png) 165 | 166 | click on browser from the task bar at bottom 167 | 168 | ![image](https://user-images.githubusercontent.com/50911878/115760771-35b3f800-a3bf-11eb-9d21-bf9c6a4c6570.png) 169 | 170 | 171 | then click on `ok` 172 | 173 | ![image](https://user-images.githubusercontent.com/50911878/115760830-47959b00-a3bf-11eb-8664-7055c444afea.png) 174 | 175 | 176 | now chrome will be open 177 | 178 | ![image](https://user-images.githubusercontent.com/50911878/115760892-5aa86b00-a3bf-11eb-8e17-d8ea0d317293.png) 179 | 180 | 181 | now create new tab and check the speed 182 | 183 | ![image](https://user-images.githubusercontent.com/50911878/115761049-89264600-a3bf-11eb-9cab-a2dc1cb0a8d6.png) 184 | 185 | 186 | ![image](https://user-images.githubusercontent.com/50911878/115761187-b4109a00-a3bf-11eb-9a13-42922debbc26.png) 187 | 188 | 189 | --------- 190 | 191 | # some extra config 192 | 193 | ### 1 hiding tab bar 194 | 195 | for hiding tab bar right click on tab and then go to panel and then panel prefrence 196 | 197 | ![image](https://user-images.githubusercontent.com/50911878/115763815-7a8d5e00-a3c2-11eb-9de4-187dcc3ca508.png) 198 | 199 | 200 | then a dialog will be open 201 | 202 | ![image](https://user-images.githubusercontent.com/50911878/115763989-a90b3900-a3c2-11eb-905d-fedfa88a90a3.png) 203 | 204 | then select 205 | 206 | ![image](https://user-images.githubusercontent.com/50911878/115764056-b9bbaf00-a3c2-11eb-97c3-28fe8bd50fcc.png) 207 | 208 | to 209 | 210 | ![image](https://user-images.githubusercontent.com/50911878/115764107-c9d38e80-a3c2-11eb-857c-fe072c91acd4.png) 211 | 212 | ![image](https://user-images.githubusercontent.com/50911878/115764150-d7891400-a3c2-11eb-9aad-25f6a2d7f47d.png) 213 | 214 | 215 | ### 2 to enable copy paste 216 | 217 | click on arrow at right side of the screen 218 | 219 | ![image](https://user-images.githubusercontent.com/50911878/115766180-49faf380-a3c5-11eb-8ffc-aedf3b6889d0.png) 220 | 221 | then click on `begin` 222 | 223 | ![image](https://user-images.githubusercontent.com/50911878/115765742-c3461680-a3c4-11eb-9305-e2797326e2b7.png) 224 | 225 | 226 | then `allow` 227 | 228 | ![image](https://user-images.githubusercontent.com/50911878/115766417-95150680-a3c5-11eb-8e3d-7526b8798ae6.png) 229 | 230 | then `ok` 231 | 232 | ![image](https://user-images.githubusercontent.com/50911878/115766486-aa8a3080-a3c5-11eb-8d68-4bb1ee555873.png) 233 | 234 | Now you can copy & paste anything from remote desktop 235 | -------------------------------------------------------------------------------- /Colab_RDP.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Colab RDP.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "display_name": "Python 3", 12 | "name": "python3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "markdown", 18 | "metadata": { 19 | "id": "iLh_9SkSut4u" 20 | }, 21 | "source": [ 22 | "# **Google Colab Remote Desktop** : \n", 23 | "Use any site or app without any restrictions.\n", 24 | "\n", 25 | "To read the step **[Collab Rdp](https://github.com/Meghdut-Mandal/Collab-Rdp)**" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "metadata": { 31 | "cellView": "form", 32 | "id": "t4yNp3KmLtZ6" 33 | }, 34 | "source": [ 35 | "#@title **Create User**\n", 36 | "#@markdown Enter Username and Password\n", 37 | "\n", 38 | "username = \"user\" #@param {type:\"string\"}\n", 39 | "password = \"root\" #@param {type:\"string\"}\n", 40 | "\n", 41 | "print(\"Creating User and Setting it up\")\n", 42 | "\n", 43 | "# Creation of user\n", 44 | "! sudo useradd -m $username &> /dev/null\n", 45 | "\n", 46 | "# Add user to sudo group\n", 47 | "! sudo adduser $username sudo &> /dev/null\n", 48 | " \n", 49 | "# Set password of user to 'root'\n", 50 | "! echo '$username:$password' | sudo chpasswd\n", 51 | "\n", 52 | "# Change default shell from sh to bash\n", 53 | "! sed -i 's/\\/bin\\/sh/\\/bin\\/bash/g' /etc/passwd\n", 54 | "\n", 55 | "print(\"User Created and Configured\")" 56 | ], 57 | "execution_count": null, 58 | "outputs": [] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "metadata": { 63 | "id": "Q6bl1b0EifVG", 64 | "cellView": "form" 65 | }, 66 | "source": [ 67 | "#@title **RDP**\n", 68 | "#@markdown It takes 4-5 minutes for installation\n", 69 | "\n", 70 | "#@markdown Visit http://remotedesktop.google.com/headless and Copy the command after authentication\n", 71 | "\n", 72 | "CRP = \"DISPLAY= /opt/google/chrome-remote-desktop/start-host --code=\\\"4/0AY0e-g7xa6YDmYpGz9XFNiHVoqU10E150l-N-0MJT5hgBIR6-JA_OheBT7sBHD3fQH9rHw\\\" --redirect-url=\\\"https://remotedesktop.google.com/_/oauthredirect\\\" --name=$(hostname)\" #@param {type:\"string\"}\n", 73 | "\n", 74 | "#@markdown Enter a pin more or equal to 6 digits\n", 75 | "Pin = 123394 #@param {type: \"integer\"}\n", 76 | "\n", 77 | "def CRD():\n", 78 | " with open('install.sh', 'w') as script:\n", 79 | " script.write(\"\"\"#! /bin/bash\n", 80 | "\n", 81 | "b='\\033[1m'\n", 82 | "r='\\E[31m'\n", 83 | "g='\\E[32m'\n", 84 | "c='\\E[36m'\n", 85 | "endc='\\E[0m'\n", 86 | "enda='\\033[0m'\n", 87 | "\n", 88 | "printf \"\\n\\n$c$b Loading Installer $endc$enda\" >&2\n", 89 | "if sudo apt-get update &> /dev/null\n", 90 | "then\n", 91 | " printf \"\\r$g$b Installer Loaded $endc$enda\\n\" >&2\n", 92 | "else\n", 93 | " printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2\n", 94 | " exit\n", 95 | "fi\n", 96 | "\n", 97 | "printf \"\\n$g$b Installing Chrome Remote Desktop $endc$enda\" >&2\n", 98 | "{\n", 99 | " wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb\n", 100 | " sudo dpkg --install chrome-remote-desktop_current_amd64.deb\n", 101 | " sudo apt install --assume-yes --fix-broken\n", 102 | "} &> /dev/null &&\n", 103 | "printf \"\\r$c$b Chrome Remote Desktop Installed $endc$enda\\n\" >&2 ||\n", 104 | "{ printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2; exit; }\n", 105 | "sleep 3\n", 106 | "\n", 107 | "printf \"$g$b Installing Desktop Environment $endc$enda\" >&2\n", 108 | "{\n", 109 | " sudo DEBIAN_FRONTEND=noninteractive \\\n", 110 | " apt install --assume-yes xfce4 desktop-base xfce4-terminal\n", 111 | " sudo bash -c 'echo \"exec /etc/X11/Xsession /usr/bin/xfce4-session\" > /etc/chrome-remote-desktop-session' \n", 112 | " sudo apt remove --assume-yes gnome-terminal\n", 113 | " sudo apt install --assume-yes xscreensaver\n", 114 | " sudo systemctl disable lightdm.service\n", 115 | "} &> /dev/null &&\n", 116 | "printf \"\\r$c$b Desktop Environment Installed $endc$enda\\n\" >&2 ||\n", 117 | "{ printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2; exit; }\n", 118 | "sleep 3\n", 119 | "\n", 120 | "printf \"$g$b Installing Google Chrome $endc$enda\" >&2\n", 121 | "{\n", 122 | " wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb\n", 123 | " sudo dpkg --install google-chrome-stable_current_amd64.deb\n", 124 | " sudo apt install --assume-yes --fix-broken\n", 125 | "} &> /dev/null &&\n", 126 | "printf \"\\r$c$b Google Chrome Installed $endc$enda\\n\" >&2 ||\n", 127 | "printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2\n", 128 | "sleep 3\n", 129 | "\n", 130 | "printf \"$g$b Installing other Tools $endc$enda\" >&2\n", 131 | "if sudo apt install nautilus nano -y &> /dev/null\n", 132 | "then\n", 133 | " printf \"\\r$c$b Other Tools Installed $endc$enda\\n\" >&2\n", 134 | "else\n", 135 | " printf \"\\r$r$b Error Occured $endc$enda\\n\" >&2\n", 136 | "fi\n", 137 | "sleep 3\n", 138 | "\n", 139 | "printf \"\\n$g$b Installation Completed $endc$enda\\n\\n\" >&2\"\"\")\n", 140 | "\n", 141 | " ! chmod +x install.sh\n", 142 | " ! ./install.sh\n", 143 | "\n", 144 | " # Adding user to CRP group\n", 145 | " ! sudo adduser $username chrome-remote-desktop &> /dev/null\n", 146 | "\n", 147 | " # Finishing Work\n", 148 | " ! su - $username -c \"\"\"$CRP --pin=$Pin\"\"\" &> /dev/null\n", 149 | "\n", 150 | " print(\"Finished Succesfully\")\n", 151 | "\n", 152 | "try:\n", 153 | " if username:\n", 154 | " if CRP == \"\":\n", 155 | " print(\"Please enter authcode from the given link\")\n", 156 | " elif len(str(Pin)) < 6:\n", 157 | " print(\"Enter a pin more or equal to 6 digits\")\n", 158 | " else:\n", 159 | " CRD()\n", 160 | "except NameError:\n", 161 | " print(\"username variable not found\")\n", 162 | " print(\"Create a User First\")" 163 | ], 164 | "execution_count": null, 165 | "outputs": [] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "metadata": { 170 | "cellView": "form", 171 | "id": "vk2qtOTGIFsQ" 172 | }, 173 | "source": [ 174 | "#@title **Google Drive Mount**\n", 175 | "#@markdown Google Drive used as Persistance HDD for files.
\n", 176 | "#@markdown Mounted at `user` Home directory inside drive folder\n", 177 | "#@markdown (If `username` variable not defined then use root as default).\n", 178 | "\n", 179 | "def MountGDrive():\n", 180 | " from google.colab import drive\n", 181 | "\n", 182 | " ! runuser -l $user -c \"yes | python3 -m pip install --user google-colab\" > /dev/null 2>&1\n", 183 | "\n", 184 | " mount = \"\"\"from os import environ as env\n", 185 | "from google.colab import drive\n", 186 | "\n", 187 | "env['CLOUDSDK_CONFIG'] = '/content/.config'\n", 188 | "drive.mount('{}')\"\"\".format(mountpoint)\n", 189 | "\n", 190 | " with open('/content/mount.py', 'w') as script:\n", 191 | " script.write(mount)\n", 192 | "\n", 193 | " ! runuser -l $user -c \"python3 /content/mount.py\"\n", 194 | "\n", 195 | "try:\n", 196 | " if username:\n", 197 | " mountpoint = \"/home/\"+username+\"/drive\"\n", 198 | " user = username\n", 199 | "except NameError:\n", 200 | " print(\"username variable not found, mounting at `/content/drive' using `root'\")\n", 201 | " mountpoint = '/content/drive'\n", 202 | " user = 'root'\n", 203 | "\n", 204 | "MountGDrive()" 205 | ], 206 | "execution_count": null, 207 | "outputs": [] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "metadata": { 212 | "cellView": "form", 213 | "id": "8icuQYnyKDLk" 214 | }, 215 | "source": [ 216 | "#@title **SSH**\n", 217 | "\n", 218 | "! pip install colab_ssh --upgrade &> /dev/null\n", 219 | "\n", 220 | "Ngrok = False #@param {type:'boolean'}\n", 221 | "Agro = False #@param {type:'boolean'}\n", 222 | "\n", 223 | "\n", 224 | "#@markdown Copy authtoken from https://dashboard.ngrok.com/auth (only for ngrok)\n", 225 | "ngrokToken = \"\" #@param {type:'string'}\n", 226 | "\n", 227 | "\n", 228 | "def runNGROK():\n", 229 | " from colab_ssh import launch_ssh\n", 230 | " from IPython.display import clear_output\n", 231 | " launch_ssh(ngrokToken, password)\n", 232 | " clear_output()\n", 233 | "\n", 234 | " print(\"ssh\", username, end='@')\n", 235 | " ! curl -s http://localhost:4040/api/tunnels | python3 -c \\\n", 236 | " \"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'][6:].replace(':', ' -p '))\"\n", 237 | "\n", 238 | "\n", 239 | "def runAgro():\n", 240 | " from colab_ssh import launch_ssh_cloudflared\n", 241 | " launch_ssh_cloudflared(password=password)\n", 242 | "\n", 243 | "\n", 244 | "try:\n", 245 | " if username:\n", 246 | " pass\n", 247 | " elif password:\n", 248 | " pass\n", 249 | "except NameError:\n", 250 | " print(\"No user found using username and password as 'root'\")\n", 251 | " username='root'\n", 252 | " password='root'\n", 253 | "\n", 254 | "\n", 255 | "if Agro and Ngrok:\n", 256 | " print(\"You can't do that\")\n", 257 | " print(\"Select only one of them\")\n", 258 | "elif Agro:\n", 259 | " runAgro()\n", 260 | "elif Ngrok:\n", 261 | " if ngrokToken == \"\":\n", 262 | " print(\"No ngrokToken Found, Please enter it\")\n", 263 | " else:\n", 264 | " runNGROK()\n", 265 | "else:\n", 266 | " print(\"Select one of them\")" 267 | ], 268 | "execution_count": null, 269 | "outputs": [] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "metadata": { 274 | "cellView": "form", 275 | "id": "OXsG6_pxeEFu" 276 | }, 277 | "source": [ 278 | "#@title Package Installer { vertical-output: true }\n", 279 | "run = False #@param {type:\"boolean\"}\n", 280 | "#@markdown *Package management actions (gasp)*\n", 281 | "action = \"Install\" #@param [\"Install\", \"Check Installed\", \"Remove\"] {allow-input: true}\n", 282 | "\n", 283 | "package = \"wget\" #@param {type:\"string\"}\n", 284 | "system = \"apt\" #@param [\"apt\", \"\"]\n", 285 | "\n", 286 | "def install(package=package, system=system):\n", 287 | " if system == \"apt\":\n", 288 | " !apt --fix-broken install > /dev/null 2>&1\n", 289 | " !killall apt > /dev/null 2>&1\n", 290 | " !rm /var/lib/dpkg/lock-frontend\n", 291 | " !dpkg --configure -a > /dev/null 2>&1\n", 292 | "\n", 293 | " !apt-get install -o Dpkg::Options::=\"--force-confold\" --no-install-recommends -y $package\n", 294 | " \n", 295 | " !dpkg --configure -a > /dev/null 2>&1 \n", 296 | " !apt update > /dev/null 2>&1\n", 297 | "\n", 298 | " !apt install $package > /dev/null 2>&1\n", 299 | "\n", 300 | "def check_installed(package=package, system=system):\n", 301 | " if system == \"apt\":\n", 302 | " !apt list --installed | grep $package\n", 303 | "\n", 304 | "def remove(package=package, system=system):\n", 305 | " if system == \"apt\":\n", 306 | " !apt remove $package\n", 307 | "\n", 308 | "if run:\n", 309 | " if action == \"Install\":\n", 310 | " install()\n", 311 | " if action == \"Check Installed\":\n", 312 | " check_installed()\n", 313 | " if action == \"Remove\":\n", 314 | " remove()" 315 | ], 316 | "execution_count": null, 317 | "outputs": [] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "metadata": { 322 | "cellView": "form", 323 | "id": "UoeBdz6_KE6a" 324 | }, 325 | "source": [ 326 | "#@title **Colab Shutdown**\n", 327 | "\n", 328 | "#@markdown To Kill NGROK Tunnel\n", 329 | "NGROK = False #@param {type:'boolean'}\n", 330 | "\n", 331 | "#@markdown To Unmount GDrive\n", 332 | "GDrive = True #@param {type:'boolean'}\n", 333 | "\n", 334 | "#@markdown To Sleep Colab\n", 335 | "Sleep = True #@param {type:'boolean'}\n", 336 | "\n", 337 | "if NGROK:\n", 338 | " ! killall ngrok\n", 339 | "\n", 340 | "if GDrive:\n", 341 | " with open('/content/unmount.py', 'w') as unmount:\n", 342 | " unmount.write(\"\"\"from google.colab import drive\n", 343 | "drive.flush_and_unmount()\"\"\")\n", 344 | " \n", 345 | " try:\n", 346 | " if user:\n", 347 | " ! runuser $user -c 'python3 /content/unmount.py'\n", 348 | " except NameError:\n", 349 | " print(\"Google Drive not Mounted\")\n", 350 | "\n", 351 | "if Sleep:\n", 352 | " ! sleep 43200" 353 | ], 354 | "execution_count": null, 355 | "outputs": [] 356 | } 357 | ] 358 | } --------------------------------------------------------------------------------