From b850a6638f3daaa562463117c04893c7c20c69b4 Mon Sep 17 00:00:00 2001 From: candifloss Date: Mon, 28 Oct 2024 10:53:24 +0530 Subject: [PATCH] Better README and comments --- README.md | 23 +++++++++++++++++++++-- ldap_basic/README.md | 23 +++++++++++++---------- ldap_basic/ldapadd.sh | 4 +++- ldap_basic/ldapmodify.sh | 4 +++- ldap_basic/ldapsearch.sh | 4 +++- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 57ac71c..8eeecc8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,22 @@ -# misc-scripts +# Miscellaneous scripts -Misc scripts I use/used for various tasks \ No newline at end of file +Various scripts I use/used for common tasks + +## Shell scripts + +Most of these shell scripts are made for posix shells, and tested only on `bash` and `zsh`, unless specified. Test on other shells and modify at your own risk. +Note that these two are equivalent: +```bash +bash scriptname.sh # Use your shell in place of bash +``` +```bash +./scriptname.sh # Requires +x permission for execution +``` + +Since `bash` and `zsh` are mostly identical in synatx, almost all scripts written for either of these work for both of them, and rarely differ in functionality, like the `()` expansions. +Quick bash reference: [bash cheatsheet](https://devhints.io/bash) +Zsh reference: [zsh cheatsheet](https://devhints.io/zsh) + +## Other scripts + +Other scripts, like the python scripts, are not limited to specific shells, but may require minor changes if they execute shell commands. diff --git a/ldap_basic/README.md b/ldap_basic/README.md index 4687142..5df3398 100644 --- a/ldap_basic/README.md +++ b/ldap_basic/README.md @@ -1,6 +1,7 @@ -# Basic LDAP operations +# Basic LDAP operations -These scripts act as shortcuts for frequently used `openldap` commands or operations. +These scripts act as shortcuts for frequently used `openldap` commands or operations. Specifying the `dn`, password, host address, etc. in a script eliminates the need to type them every time you have to do something. +Keep the scripts and credentials away from unauthorized personnel. Use at your own risk. ## Common openldap commands and options @@ -17,25 +18,27 @@ You will have to modify these fields in the scripts: - `-b`: Search base: `dc=example,dc=com` - `-f`: File: The `.ldif` file with the `ldif` data to add or modify an entry -Usage examples: +Command examples: ```bash -ldapsearch -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://ldap.example.com/ -b dc=example,dc=com uid=tomsawyer +ldapsearch -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://ldap.example.com/ -b dc=example,dc=com uid=tomsawyer ``` ```bash -ldapadd -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://192.12.34.123/ -f testuser.ldif +ldapadd -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://192.12.34.123/ -f testuser.ldif ``` -## Script usage +Refer the openldap man pages or documentations for more information including full lists of options and argumenst for each command, syntax for `ldif` files, ldap filters, `oid` and attributes, etc. -[ldapsearch.sh](ldapsearch.sh): Search entry by any attribute +## Script usage + +[ldapsearch.sh](ldapsearch.sh): Search entries by any attribute ```bash -bash ldapsearch.sh uid=tomsawyer +bash ldapsearch.sh uid=tomsawyer # Takes any number of arguments ``` [ldapadd.sh](ldapadd.sh): Add entries from ldif file ```bash -bash ldapadd.sh filename.ldif +bash ldapadd.sh filename.ldif # Takes 1 filename as argument ``` [ldapmodify.sh](ldapmodify.sh): Modify entries with info from ldif file ```bash -bash ldapmodify.sh filename.ldif +bash ldapmodify.sh filename.ldif # Takes 1 filename as argument ``` \ No newline at end of file diff --git a/ldap_basic/ldapadd.sh b/ldap_basic/ldapadd.sh index 48cdd3c..b8c73fa 100644 --- a/ldap_basic/ldapadd.sh +++ b/ldap_basic/ldapadd.sh @@ -1 +1,3 @@ -ldapadd -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://192.12.34.123/ -f $1 \ No newline at end of file +ldapadd -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://192.12.34.123/ -f $1 +# This script takes one argument - the /path/filenam.ldif of an ldif file. +# Refer the documentations for ldif syntax. \ No newline at end of file diff --git a/ldap_basic/ldapmodify.sh b/ldap_basic/ldapmodify.sh index 43a4e5d..0aa3123 100644 --- a/ldap_basic/ldapmodify.sh +++ b/ldap_basic/ldapmodify.sh @@ -1 +1,3 @@ -ldapmodify -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://192.12.34.123/ -f $1 \ No newline at end of file +ldapmodify -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -H ldap://192.12.34.123/ -f $1 +# This script takes one argument - the /path/filenam.ldif of an ldif file. +# Refer the documentations for ldif syntax. \ No newline at end of file diff --git a/ldap_basic/ldapsearch.sh b/ldap_basic/ldapsearch.sh index e23f901..97772d8 100644 --- a/ldap_basic/ldapsearch.sh +++ b/ldap_basic/ldapsearch.sh @@ -1 +1,3 @@ -ldapsearch -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -b dc=example,dc=com $* \ No newline at end of file +ldapsearch -D cn=ldapadmin,dc=example,dc=com -w Y0ur4dm!nPwd -b dc=example,dc=com $* +# Takes any number of arguments: atrib=value or '(filter)' +# If no arguments specified, it perform `ldapsearch` without arguments and prints all the matching results \ No newline at end of file