Linux/Unix: Bash Set Shell Variable Command

In the bash shell, you can set the value of a shell variable using the following syntax: variable_name=value For example: message=”Hello World” This sets the value of the message variable to “Hello World”. You can also set a variable to the result of a command: current_date=$(date) This sets the value of the current_date variable to … Read more

Unix / Linux Shell: Get Third Field Separated by Forward Slash (/) Delimiter

To extract the third field separated by forward slash (/) delimiter in Unix/Linux shell, you can use the following command: echo “field1/field2/field3/field4” | awk -F’/’ ‘{print $3}’ This uses the awk command to split the input string on forward slashes (/) and then prints the third field ($3). The -F option is used to specify … Read more

HowTo: Nginx Block User Agent

You can block specific user agents in Nginx by using the if directive in the server block. Here’s an example: server { … if ($http_user_agent ~* (bad-agent1|bad-agent2)) { return 403; } … } This example blocks requests from user agents that contain the string “bad-agent1” or “bad-agent2”. The return statement returns a HTTP status code … Read more