Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Media is too big
VIEW IN TELEGRAM
Django interactive shell

#python #django #shell #django_part7
Get current directory from within the bash script:

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
Mastering Linux Shell Scripting

#ebook #book #shell #scripting #linux #pub
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:

> 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 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
Did you know you can test bash scripts line by line? Well, 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 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 is
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
In order to enable bash completion in Kubernetes you can usee the below command in linux bash:

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