├── LICENSE ├── README.md └── scripts.json /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 bhr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BHRShellScriptLibrary 2 | ===================== 3 | 4 | What is the Shell Script Library? 5 | --------------------------------- 6 | The Script Library is a collection of useful bash scripts, which can be accessed by all SimplePi users. 7 | 8 | Everyone can contribute to the Script Library and make his scripts available for other users. 9 | 10 | 11 | We're happy to help you, if you need assisstance adding your scripts or have problems adding them. 12 | 13 | 14 | How to Contribute 15 | ----------------- 16 | You can add scripts by creating a pull request to the main Script Library repository. 17 | 18 | 1. Fork BHRScriptLibrary. 19 | 2. Add your scripts to `scripts.json` by respecting the script guidelines. 20 | 3. Validate `scripts.json` with 21 | 4. Press the green button in the upper left corner, review your changes and submit the pull request via `Create Pull Request`. 22 | 5. After being reviewed, your scripts will be part of the Script Library. 23 | 24 | 25 | Script Guidelines 26 | ---------------------- 27 | 28 | All scripts are located in `scripts.json`. 29 | The basic structure is a an array of `Groups`, that have children. Each child is a `Command`. 30 | 31 | File Structure Illustration: 32 | ``` 33 | [ 34 | Group [ 35 | Command, 36 | Command 37 | ], 38 | Group [ 39 | Command, 40 | Command, 41 | Command 42 | ] 43 | ] 44 | ``` 45 | 46 | A `Group` must have the following properties: 47 | 48 | * Name 49 | * Description 50 | * UID 51 | * Children (Array of Commands) 52 | 53 | A `Command` must have the following properties: 54 | 55 | * Name 56 | * Description 57 | * Script 58 | * Show Result 59 | * Timeout (0 is no timeout) 60 | * UID 61 | 62 | For UID generation please use . 63 | 64 | 65 | 66 | Additional Resources: 67 | --------------- 68 | * 69 | * 70 | * 71 | * 72 | 73 | 74 | 75 | Disclaimer 76 | ---------- 77 | No guarantee is provided that the scripts will function properly on your system. Some require additional packages. No warranty for loss or corruption of any data. 78 | 79 | Use the scripts at your own risk! 80 | -------------------------------------------------------------------------------- /scripts.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "children": [ 4 | { 5 | "description": "Prints out current CPU utilization", 6 | "name": "Show CPU", 7 | "script": "top -b -n2 | grep \"Cpu(s)\" | awk '{print $8 \",\"}';", 8 | "showResult": true, 9 | "timeout": 0, 10 | "uid": "1CE0BC40-C03F-40FF-8EF5-F067B78695D1" 11 | }, 12 | { 13 | "description": "Prints out current free Memory", 14 | "name": "Show free Memory", 15 | "script": "free;", 16 | "showResult": true, 17 | "timeout": 0, 18 | "uid": "F5C16B0B-B176-4F59-A83E-03287549FE66" 19 | }, 20 | { 21 | "description": "Prints out running processes of the current user", 22 | "name": "Show this user's running Processes", 23 | "script": "ps;", 24 | "showResult": true, 25 | "timeout": 0, 26 | "uid": "1B13F2E9-727B-4865-ADD9-7240E3C730E0" 27 | }, 28 | { 29 | "description": "Prints out running processes of all users", 30 | "name": "Show all user's running Processes", 31 | "script": "ps -e;", 32 | "showResult": true, 33 | "timeout": 0, 34 | "uid": "551EDCD5-7624-45D8-9F60-80737362FCC0" 35 | }, 36 | { 37 | "description": "Prints out all running processes in a tree", 38 | "name": "Show running Processes Tree", 39 | "script": "pstree;", 40 | "showResult": true, 41 | "timeout": 0, 42 | "uid": "BBFC858C-70C3-41CA-ABB3-1F4F66ED458C" 43 | }, 44 | { 45 | "description": "Prints out system uptime", 46 | "name": "Show System Uptime", 47 | "script": "uptime;", 48 | "showResult": true, 49 | "timeout": 0, 50 | "uid": "DDA382D2-A4B3-46B7-8A0D-2A4C680F62A4" 51 | } 52 | ], 53 | "description": "Scripts for monitoring CPU, Memory, etc", 54 | "name": "System Monitoring", 55 | "uid": "BEBBA2D6-FB52-400E-BB5F-4B8FD2C051F0" 56 | }, 57 | { 58 | "children": [ 59 | { 60 | "description": "Prints out CPU information", 61 | "name": "Show CPU Info", 62 | "script": "cat /proc/cpuinfo", 63 | "showResult": true, 64 | "timeout": 0, 65 | "uid": "06EF6D64-4BB3-4AF7-A52B-4981DE613B8E" 66 | }, 67 | { 68 | "description": "Prints out Memory information", 69 | "name": "Show Memory Info", 70 | "script": "cat /proc/meminfo;", 71 | "showResult": true, 72 | "timeout": 0, 73 | "uid": "E499D11C-1CD5-4B94-B1A9-7C6FA10DBE6E" 74 | }, 75 | { 76 | "description": "Prints disk usage of all mounted drives", 77 | "name": "Show Disk Status", 78 | "script": "df -h;", 79 | "showResult": true, 80 | "timeout": 0, 81 | "uid": "4C71C399-05C0-4014-B586-BD956E9540AF" 82 | }, 83 | { 84 | "description": "Prints current version of the device", 85 | "name": "Show Current Version", 86 | "script": "cat /proc/version", 87 | "showResult": true, 88 | "timeout": 0, 89 | "uid": "0A46EB7F-CCA6-4F0D-8672-D0E52A506EB0" 90 | }, 91 | { 92 | "description": "List attached USB devices", 93 | "name": "Show USB Devices", 94 | "script": "lsusb;", 95 | "showResult": true, 96 | "timout": 0, 97 | "uid": "5DAEBE69-B83B-4DDE-82D3-77E95E5E1455" 98 | }, 99 | { 100 | "description": "Prints the system's external IP address", 101 | "name": "Show External IP Address", 102 | "script": "curl ifconfig.me;", 103 | "showResult": true, 104 | "timout": 60, 105 | "uid": "5DACBF45-36EC-4133-B81E-833A817FD15E" 106 | } 107 | ], 108 | "description": "Display General System Information", 109 | "name": "Hardware Information", 110 | "uid": "B257AB73-8985-42D2-A056-983FA4ECE8A9" 111 | }, 112 | { 113 | "children": [ 114 | { 115 | "description": "Displays last 5 logged in users", 116 | "name": "Shows last Users", 117 | "script": " last -n 5", 118 | "showResult": true, 119 | "timeout": 0, 120 | "uid": "FB4D4E8C-3DF8-41A1-A11E-6EB2704E726C" 121 | }, 122 | { 123 | "description": "Prints last 30 Auth Log Lines", 124 | "name": "Show Last Authorizations", 125 | "script": "tail -30 /var/log/auth.log;", 126 | "showResult": true, 127 | "timeout": 0, 128 | "uid": "D9061271-B237-42DF-BB74-ABB3F4C4EF00" 129 | }, 130 | { 131 | "description": "Show who is logged on and what they're doing", 132 | "name": "Show Logged on Users", 133 | "script": "w;", 134 | "showResult": true, 135 | "timeout": 0, 136 | "uid": "60989A97-56B7-4E1C-A291-CDAAA8AD0C0E" 137 | } 138 | ], 139 | "description": "Display Information about last logins, current user, etc.", 140 | "name": "Login Information", 141 | "uid": "0FE5D0F9-DF48-4854-9F9A-8FE998AF367A" 142 | }, 143 | { 144 | "children": [ 145 | { 146 | "description": "Safely shutdown", 147 | "name": "Shutdown", 148 | "script": " shutdown now;", 149 | "showResult": false, 150 | "timeout": 10, 151 | "uid": "C99921C9-4F18-45EC-A042-F59E0009EC8A" 152 | }, 153 | { 154 | "description": "Reboots the system", 155 | "name": "Reboot", 156 | "script": "shutdown -r now;", 157 | "showResult": false, 158 | "timeout": 10, 159 | "uid": "2E41199D-91A8-4779-B73D-FFC74A54D6B4" 160 | } 161 | ], 162 | "description": "Shutting down and restarting the system", 163 | "name": "System Restart/Shutdown", 164 | "uid": "557C127C-7C66-49C7-809A-B4631CF1C94F" 165 | }, 166 | { 167 | "children": [ 168 | { 169 | "description": "Automatically update and upgrade all software packages", 170 | "name": "Update and Upgrade - apt", 171 | "script": "apt-get update; apt-get -y upgrade;", 172 | "showResult": false, 173 | "timeout": 10, 174 | "uid": "9704FA23-33E4-46D2-B67E-439415AB615B" 175 | } 176 | ], 177 | "description": "Updating, Upgrading Software Packages and other tasks", 178 | "name": "System Maintenance", 179 | "uid": "AF150AC8-D745-4E8E-905A-D6E84DDB9312" 180 | }, 181 | { 182 | "children": [ 183 | { 184 | "description": "Mounts a remote drive via NFS", 185 | "name": "Mount NFS", 186 | "script": "#To enable NFS share mounting on raspbian, please see: http://www.raspbian.org/RaspbianFAQ#How_do_I_mount_directories_from_other_Linux.2FUnix.2FBSD_servers.3F__How_do_I_mount_an_NFS_share.3F\n#\nip_address=<#ip_to_nfs_drive#>;\nnfs_path=<#my_local_path_on_nfs_drive#>;\nlocal_mount_path=<#my_local_mount_path#>;\n\nmkdir -p $local_mount_path; sudo mount $ip_address:$nfs_path $local_mount_path;", 187 | "showResult": false, 188 | "timeout": 0, 189 | "uid": "325C7C3D-4E87-44EB-8956-B3EF733BD95B" 190 | }, 191 | { 192 | "description": "Unmounts a remove drive connected via NFS", 193 | "name": "Unmount NFS", 194 | "script": "local_mount_path=<#my_local_mount_path#>;\nsudo umount -l -f $local_mount_path;", 195 | "showResult": false, 196 | "timeout": 0, 197 | "uid": "484F315D-D0CF-4416-9F0E-3C67C649755B" 198 | }, 199 | { 200 | "description": "Mounts a remote CIFS/SMB file system", 201 | "name": "Mount CIFS/SMB", 202 | "script": "ip_address=<#ip_to_server#>;\nshare_name=<#share_name#>;\nlocal_mount_path=<#my_local_mount_path#>;\nusername=<#myusername#>;\npassword=<#mypassword#>;\n\nsudo mkdir -p $local_mount_path;\nsudo mount -t cifs //$ip_address/$share_name $local_mount_path -o username=$username,password=$password;", 203 | "showResult": false, 204 | "timeout": 0, 205 | "uid": "E2670E41-F80D-4707-8982-A3A312BA5B40" 206 | }, 207 | { 208 | "description": "Unmounts a remote CIFS/SMB file system", 209 | "name": "Unmount CIFS/SMB", 210 | "script": "local_mount_path=<#my_local_mount_path#>;\nsudo umount -l -f $local_mount_path;", 211 | "showResult": false, 212 | "timeout": 0, 213 | "uid": "1551F355-D3A8-4CB1-A519-44743E49A470" 214 | }, 215 | { 216 | "description": "Prints all network interfaces currently in operation.", 217 | "name": "Current Network Interfaces", 218 | "script": "ifconfig;", 219 | "showResult": true, 220 | "timout": 60, 221 | "uid": "1bf5c8cf-6844-4c73-b933-c3177f4e33f7" 222 | }, 223 | { 224 | "description": "Restart Network Services", 225 | "name": "Reset Network Services", 226 | "script": "sudo /etc/init.d/networking restart", 227 | "showResult": true, 228 | "timout": 60, 229 | "uid": "e2d5cfda-3573-4e2e-9523-39a3bac0b121" 230 | } 231 | ], 232 | "description": "All Commands about Networking", 233 | "name": "Networking", 234 | "uid": "D0C2C70B-E2B3-4888-8C41-67068BA30BC8" 235 | }, 236 | { 237 | "children": [ 238 | { 239 | "description": "Searches for a given string", 240 | "name": "Text search", 241 | "script": "searchText=<#mySearchText#>;\nfilename=<#myfile#>;\ngrep \"$searchText\" $filename", 242 | "showResult": true, 243 | "timeout": 0, 244 | "uid": "D910451D-9D1E-4915-96F4-D52822BD8C4F" 245 | }, 246 | { 247 | "description": "Searches for a given string case insensitive", 248 | "name": "Text search (Case insensitive)", 249 | "script": "searchText=<#mySearchText#>;\nfilename=<#myfile#>;\ngrep -i \"$searchText\" $filename", 250 | "showResult": true, 251 | "timeout": 0, 252 | "uid": "1F6A6A06-78C6-45A6-8829-51A46613B28F" 253 | }, 254 | { 255 | "description": "Searches for a given word case insensitive", 256 | "name": "Word search", 257 | "script": "searchText=<#mySearchText#>;\nfilename=<#myfile#>;\ngrep -iw \"$searchText\" $filename", 258 | "showResult": true, 259 | "timeout": 0, 260 | "uid": "FC452339-F82E-4E5A-8BA4-08B86B97102D" 261 | }, 262 | { 263 | "description": "Searches for a given string at the beginning of a line", 264 | "name": "Lines starting with text", 265 | "script": "searchText=<#mySearchText#>;\nfilename=<#myfile#>;\ngrep \"^$searchText.*\" $filename", 266 | "showResult": true, 267 | "timeout": 0, 268 | "uid": "9B7D603E-F016-46BB-AFCC-738D88633401" 269 | }, 270 | { 271 | "description": "Searches for a given string at the end of a line", 272 | "name": "Lines ending with text", 273 | "script": "searchText=<#mySearchText#>;\nfilename=<#myfile#>;\ngrep \".*$searchText$\" $filename", 274 | "showResult": true, 275 | "timeout": 0, 276 | "uid": "16DA7332-2457-4C5C-918E-1FDD09B22A4F" 277 | }, 278 | { 279 | "description": "Displays all file names that match a given pattern", 280 | "name": "Show files matching string", 281 | "script": "searchText=<#mySearchText#>;\nfilename=<#myfile#>;\ngrep -l \"$searchText\" $filename", 282 | "showResult": true, 283 | "timeout": 0, 284 | "uid": "BB3A55F9-1DEB-4B0D-BD60-9DAB97AC9001" 285 | }, 286 | { 287 | "description": "Displays the number of occurrences of a pattern in a given file", 288 | "name": "Occurrences of text in file", 289 | "script": "searchText=<#mySearchText#>;\nfilename=<#myfile#>;\nsort $filename | uniq -c | sort -nr | grep \"$searchText\"", 290 | "showResult": true, 291 | "timeout": 0, 292 | "uid": "9ED687D6-CB3C-42AC-A406-A122234F0DFA" 293 | } 294 | ], 295 | "description": "Searching in Files and Folders", 296 | "name": "Search", 297 | "uid": "0BFA9C70-2A63-42A6-820C-476E508ABBC6" 298 | }, 299 | { 300 | "children": [ 301 | { 302 | "description": "Synchronizes two folders and preserves metadata", 303 | "name": "Synchronize two folders", 304 | "script": "source=<#source#>;\ndestination=<#destination#>;\nrsync -azv $source $destination;", 305 | "showResult": true, 306 | "timeout": 0, 307 | "uid": "52676F06-E1BF-4F17-ACB2-A6F066A0D050" 308 | }, 309 | { 310 | "description": "Synchronize two folders and delete orphaned files at target", 311 | "name": "Backup Folder", 312 | "script": "source=<#source#>;\ndestination=<#destination#>;\nrsync -azv --delete $source $destination;", 313 | "showResult": true, 314 | "timeout": 0, 315 | "uid": "DC8E0E7D-2C05-4CA2-AB83-1F5905D48FD3" 316 | } 317 | ], 318 | "description": "Synchronize and Backup Files and Folders", 319 | "name": "Synchronize & Backup", 320 | "uid": "787FE92D-8BFF-40AC-84D7-6985E94FA64A" 321 | }, 322 | { 323 | "children": [ 324 | { 325 | "description": "List files with no options", 326 | "name": "List files (no option)", 327 | "script": "folder=<#folder#>;\nls $folder", 328 | "showResult": true, 329 | "timeout": 0, 330 | "uid": "D3DF3E5C-F9F3-4AE4-A2C4-3EFAD594BC89" 331 | }, 332 | { 333 | "description": "List one file per line", 334 | "name": "List files single line", 335 | "script": "folder=<#folder#>;\nls -1 $folder", 336 | "showResult": true, 337 | "timeout": 0, 338 | "uid": "2C6CCA74-75D1-49B7-8BDD-9C1B5F677228" 339 | }, 340 | { 341 | "description": "List files with permissions & size", 342 | "name": "List files detailed", 343 | "script": "folder=<#folder#>;\nls -lh $folder", 344 | "showResult": true, 345 | "timeout": 0, 346 | "uid": "9DC08D6D-9515-4F66-9AE6-6E2720A713D6" 347 | }, 348 | { 349 | "description": "List files including hidden ones", 350 | "name": "List hidden files", 351 | "script": "folder=<#folder#>;\nls -a $folder", 352 | "showResult": true, 353 | "timeout": 0, 354 | "uid": "53FE148A-CD4D-4AA0-8B63-68D08B73F56D" 355 | }, 356 | { 357 | "description": "List all sub directories and their contents", 358 | "name": "List directory tree recursively", 359 | "script": "folder=<#folder#>;\nls -R $folder", 360 | "showResult": true, 361 | "timeout": 0, 362 | "uid": "28B75316-641F-40E3-BF5B-47B59198B3D9" 363 | }, 364 | { 365 | "description": "List all files sorted by file size", 366 | "name": "List files by size", 367 | "script": "folder=<#folder#>;\nls -lSh $folder", 368 | "showResult": true, 369 | "timeout": 0, 370 | "uid": "93C64D03-2672-4250-9683-4EAA71B024FE" 371 | }, 372 | { 373 | "description": "Shows the size of the contents of the directory", 374 | "name": "Show size of directory", 375 | "script": "folder=<#folder#>;\ndu -sh $folder", 376 | "showResult": true, 377 | "timeout": 0, 378 | "uid": "0EDD0312-7476-4CD8-A0B6-03F829B89E25" 379 | } 380 | ], 381 | "description": "List Files and contents of Folders", 382 | "name": "List Files and Folders", 383 | "uid": "38F06000-679F-441A-B58C-A1BD56EBA902" 384 | }, 385 | { 386 | "children": [ 387 | { 388 | "description": "Grant ownership of file/folder", 389 | "name": "Grant ownership to user", 390 | "script": "user=<#user#>;\nfile=<#file_path#>;\necho \"before:\" && ls -l $file;\nsudo chown $user $file;echo \"after:\" && ls -l $file;\n", 391 | "showResult": true, 392 | "timeout": 0, 393 | "uid": "3854CF8E-429C-489B-B01A-45591E743A58" 394 | }, 395 | { 396 | "description": "Assign a file/folder to a group", 397 | "name": "Assign to group", 398 | "script": "user=<#user#>;\nfile=<#file_path#>;\necho \"before:\" && ls -l $file;\nsudo chgrp $group $file;echo \"after:\" && ls -l $file;\n", 399 | "showResult": true, 400 | "timeout": 0, 401 | "uid": "8F647A96-B381-4185-BE5A-7E8088B99574" 402 | }, 403 | { 404 | "description": "Change permissions to User rwx, Group r-x, World r-x", 405 | "name": "Read/Execute World (755)", 406 | "script": "file=<#file_path#>;\necho \"before:\" && ls -l $file;\nchmod 755 $file;echo \"after:\" && ls -l $file;\n", 407 | "showResult": true, 408 | "timeout": 0, 409 | "uid": "B0A8A212-844F-4D1F-9B0C-092326ED710F" 410 | }, 411 | { 412 | "description": "Change permissions to User rwx, Group r-x, World ---", 413 | "name": "Read/Execute Group (750)", 414 | "script": "file=<#file_path#>;\necho \"before:\" && ls -l $file;\nchmod 750 $file;echo \"after:\" && ls -l $file;\n", 415 | "showResult": true, 416 | "timeout": 0, 417 | "uid": "C578D566-C754-4C9C-9EED-BC2E0E50829C" 418 | }, 419 | { 420 | "description": "Change permissions to User r--, Group r--, World r--", 421 | "name": "Read Only (444)", 422 | "script": "file=<#file_path#>;\necho \"before:\" && ls -l $file;\nchmod 444 $file;echo \"after:\" && ls -l $file;\n", 423 | "showResult": true, 424 | "timeout": 0, 425 | "uid": "12449B62-A0D1-4437-ADBB-6FCBA7A16256" 426 | }, 427 | { 428 | "description": "Change permissions to User rw-, Group r--, World r--", 429 | "name": "Owner Read & Write (644)", 430 | "script": "file=<#file_path#>;\necho \"before:\" && ls -l $file;\nchmod 644 $file;echo \"after:\" && ls -l $file;\n", 431 | "showResult": true, 432 | "timeout": 0, 433 | "uid": "500B38BE-E707-49A5-B221-43DFD6D3EB44" 434 | } 435 | ], 436 | "description": "Basic File Permission Commands", 437 | "name": "File Permissions", 438 | "uid": "31F7F568-8CCA-4F2B-8F8E-BCF4FFE233A3" 439 | }, 440 | { 441 | "children": [ 442 | { 443 | "decription": "Restart NZBGet", 444 | "name": "Restart NZBGet", 445 | "script": "sudo service nzbget restart;", 446 | "showResult": true, 447 | "timeout": 0, 448 | "uid": "598e7a85-84ff-455f-b8e6-75af94139150" 449 | } 450 | ], 451 | "description": "Start/Stop/Restart Media Services", 452 | "name": "Media Center Control", 453 | "uid": "bb8fd250-6151-42f7-a575-9a94ebb9c8e7" 454 | } 455 | ] --------------------------------------------------------------------------------