Get current directory from within the bash script:
#linux #bash #script #shell #pwd #current_directory
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
echo "$SCRIPT_DIR"
dirname
gets the current directory and cd
will change the current directory, finally pwd
will return the current working directory, which in our case will be stored in SCRIPT_DIR
.#linux #bash #script #shell #pwd #current_directory
Did you know that the mongoDB shell is a full-featured JavaScript interpreter, capable of running arbitrary JavaScript programs? To illustrate this, let’s perform some basic math:
We can also leverage all of the standard JavaScript libraries:
We can even define and call JavaScript functions. In previous posts we explained how to kill slow queries, there we explained how to define a function in MongoDB and store that function inside of MongoDB.
#mongodb #mongo #shell #javascript #js
> x = 200
200
> x / 5;
40
We can also leverage all of the standard JavaScript libraries:
> Math.sin(Math.PI / 2);
1
> new Date("2010/1/1");
"Fri Jan 01 2010 00:00:00 GMT-0500 (EST)"
> "Hello, World!".replace("World", "MongoDB"); Hello, MongoDB!
We can even define and call JavaScript functions. In previous posts we explained how to kill slow queries, there we explained how to define a function in MongoDB and store that function inside of MongoDB.
#mongodb #mongo #shell #javascript #js
How to print a sentence when users on the server run mongo shell?
For
By default
That's it! Save the file and run
In order to disable dangerous functionalities:
Sample output:
#mongodb #mongo #shell #mongorc
For
DBAs
to limit some dangerous functionalities like dropping a database or it can be a helpful message. Or a greeting message. Or even printing the default database that he is already connected to.By default
mongoDB
looks for a file named .mongorc.js
in your home directory. So create a file ~/.mongorc.js
and put a content like below inside of it:print("Hello! Welcome to Alireza company :)");
print("Your database is set to: " + db);
That's it! Save the file and run
mongo
in your terminal, the output should be similar to the following:$ mongo
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.2
Your database is set to: test
Hello! Welcome to Alireza company :)
>
In order to disable dangerous functionalities:
var no = function() { print("oops! You are not allowed to drop anything!!");};
// Prevent dropping databases
db.dropDatabase = DB.prototype.dropDatabase = no;
// Prevent dropping collections
DBCollection.prototype.drop =no;
// Prevent dropping indexes
DBCollection.prototype.dropIndex = no;
Sample output:
> db.dropDatabase('bi')
oops! You are not allowed to drop anything!!.
NOTE:
You can disable loading your .mongorc.js
by using the --norc
option when starting the shell.#mongodb #mongo #shell #mongorc
https://unix.stackexchange.com/questions/31414/how-can-i-pass-a-command-line-argument-into-a-shell-script
#shell #argument #pass_argument #command_line #terminal #linux #bash #script
#shell #argument #pass_argument #command_line #terminal #linux #bash #script
Unix & Linux Stack Exchange
How can I pass a command line argument into a shell script?
I know that shell scripts just run commands as if they were executed in at the command prompt. I'd like to be able to run shell scripts as if they were functions... That is, taking an input value or
Did you know you can test bash scripts line by line? Well,
The content of the bash script is:
#bash #sh #shell #scripting #debug #debugging
bash -x
is here to help:$ bash -x your_script.sh
+ a=10
+ echo 10
10
The content of the bash script is:
#!/bin/bash
a=10
echo $a
#bash #sh #shell #scripting #debug #debugging
In
gist in github for it:
- https://gist.github.com/SanderTheDragon/1331397932abaa1d6fbbf63baed5f043
Download shell and run it! (Be careful and read any shell script before running it, I've read it myself)
Now you can add it to favorites and have instant access to it.
Spread your love for m2sh :)))
#postman #debian #ubuntu #shell #gist #github
Debian
based OSes if you want to install Postman
you need to download the binary package and run it everytime you need. But there is a better way for it that you can access Postman
system wide. There isgist in github for it:
- https://gist.github.com/SanderTheDragon/1331397932abaa1d6fbbf63baed5f043
Download shell and run it! (Be careful and read any shell script before running it, I've read it myself)
Now you can add it to favorites and have instant access to it.
Spread your love for m2sh :)))
#postman #debian #ubuntu #shell #gist #github
Gist
A shellscript to create a Postman .deb file, for simple installation on Debian-based Linux distro's. Also creates a .desktop file.
A shellscript to create a Postman .deb file, for simple installation on Debian-based Linux distro's. Also creates a .desktop file. - postman-deb.sh
In order to enable bash completion in Kubernetes you can usee the below command in linux bash:
Now to test this enter the below command and you should see the completion:
It should be expanded to
#linux #bash #shell #kubernetes #kubectl
source <(kubectl completion bash)
Now to test this enter the below command and you should see the completion:
kubectl cl<TAB>
It should be expanded to
kubectl cluster-info
.#linux #bash #shell #kubernetes #kubectl
pdsh
: a high performance, parallel remote shell utility. Pdsh is a multithreaded remote shell client which executes commands on multiple remote hosts in parallel. Pdsh can use several different remote shell services, including standard "rsh", Kerberos IV, and ssh.To see more about it head over to:
- https://github.com/grondo/pdsh
#linux #shell #pdsh #shell
GitHub
GitHub - grondo/pdsh: A high performance, parallel remote shell utility
A high performance, parallel remote shell utility. Contribute to grondo/pdsh development by creating an account on GitHub.