ShellHacks
42 subscribers
167 links
www.ShellHacks.com | Command-Line Tips & Tricks
Download Telegram
🌐 Python: Download File from URL & Save

A Python can be used to download a text or a binary data from a URL by reading the response of a urllib.request.urlopen.

The downloaded data can be stored as a variable and/or saved to a local drive as a file.

Below you will find the examples of the Python code snippets for downloading the different types of files from URLs and storing them as variables or saving locally.

πŸ“– Continue Reading
🌐 Python: Sleep Random Time – Web Scraping

Some websites can block access to prevent web scraping, that can be easily detected if your Python script is sending multiple requests in a short period of time.

To not get banned you can try to add random delays between queries.

For this you can use the Python's sleep() function that suspends (waits) execution of the current thread for a given number of seconds with the randint() function that returns a random integer.

πŸ“– Continue Reading
🌐 Git Bash: Clear History

The history -cw command is used to clear a Bash history on Linux, but for some reason it doesn't work for a Git Bash on Windows.

If you try to clear the commands history in the Git Bash using this command, it won't work - you will still see the history of the executed commands after the application restart.

To completely erase the Git Bash history you need to locate and delete the .bash_history file and then run the history -c command.

πŸ“– Continue Reading
🌐 Kubernetes: Deployment Is Not Creating Pods

Imagine the situation, when you are starting a Deployment of some application on a Kubernetes cluster by running, for example, the kubectl create deployment command.

Then you execute the kubectl get pods command to list the Pods, but it returns "No resource found", that means the Deployment hasn't created any Pods.

Below i will show you how to start troubleshooting when the Deployment is not creating the Pods on a Kubernetes cluster.

πŸ“– Continue Reading
🌐 Change Computer Name – Windows CMD & PowerShell

To show a computer's name in Windows, simply execute the hostname command from a Windows command prompt (CMD) or PowerShell.

There may be multiple reasons to rename the computer.

In this article, i will show you how to change your computer's name in Windows using the CMD and PowerShell.

πŸ“– Continue Reading
🌐 Windows: Migrate Domain User Profile To Local

If you are leaving a company and keep your corporate laptop, that is in a company's AD domain (e.g. AzureAD), with you, you may wonder how to keep your user's profile settings and data before removing it from the domain.

Unfortunately, by the moment, Microsoft doesn't propose any official tool to migrate the domain user profile to the local one (at least i couldn't find one).

Nevertheless, there is a tool called "User Profile Wizard", created by ForensiT's, that can be used to copy the domain user profile to the local one and in this article I will show you how to do this.

πŸ“– Continue Reading
🌐 Windows: Get a User’s SID – CMD & PowerShell

Any user, group or computer in Windows has a unique SID (security identifier) assigned.

The SIDs are used to control access to various Windows resources like files, registry keys, network shares, etc.

Below i will show you how to get the user's SID and how to do the reverse SID lookup (get the user name by SID) using the Windows command prompt or PowerShell.

πŸ“– Continue Reading
🌐 Docker Compose: Pull Latest Image Version

The docker-compose up command doesn't check a registry for a newer version of an image if it finds the image:latest among the locally cached images.

So after a while you may find, that despite of the :latest tag of the image in a docker-compose.yml file, the docker-compose up command doesn't pull the latest version of this image even though it is available in the registry.

Below i will show how to force the docker-compose up command to pull the latest version of the images.

πŸ“– Continue Reading
🌐 Start Maximized | Minimized Program – CMD (Batch)

A START command is used to run a program or command in a separate window from a Windows command prompt (CMD).

The new window can be started as maximized or minimized, that can be controlled using the /MAX or /MIN switches correspondingly.

Below i will show how to start a program in the maximized or minimized window from the Windows command prompt (CMD) or a batch file.

πŸ“– Continue Reading
🌐 Ansible Playbook β€œDry Run” – Check Mode

An Ansible's "dry run" or check mode feature is just a simulation of the execution of the ansible-playbook command.

When the ansible-playbook command is executed in the check mode, it will not make any changes on a target system.

With the Ansible's "dry run" feature you can see if the target system is getting changed or not before actually applying the playbook and making any changes on the target host.

πŸ“– Continue Reading
🌐 SSHPass: SSH Login With Password – Command Line

A password-based authentication is often a default way to connect to a remote host over SSH.

But as it requires a user to enter a password manually, this creates some complicity if you need to automate the SSH login.

This note shows how to login over SSH by passing the password as a parameter on a command-line using the sshpass command.

πŸ“– Continue Reading
🌐 Find Out Text File Line Endings – LF or CLRF

A newline (also known as a line ending, end of line (EOL) or line break) is a character used to represent the end of a line of text and the beginning of a new line.

Text files created on DOS/Windows machines have different line endings than files created on Unix/Linux.

This note shows how to find out the line endings in a text file and how to change them.

πŸ“– Continue Reading
🌐 What Active Directory Groups Am I In?

If your computer is running in a corporate environment, one day you may wonder which Active Directory (AD) groups your current user is a member of.

The easiest way to see what AD groups i am a member of is by executing the appropriate commands from a command prompt (CMD or PowerShell) and this short note shows how to do this.

πŸ“– Continue Reading
🌐 Screen: Rename Session

A named screen session can be started by using the screen -S <sessionName> command.

If you start a simple screen session, by default, it will be named as something like 55355.pts-0.hostname.

No matter how the screen session has been started, it can be easily renamed at any time.

This short note shows how to rename a GNU screen session in Linux.

πŸ“– Continue Reading
🌐 Kubectl: Set Default Namespace – Kubernetes

Out of the box, there is a Namespace called 'default' in a Kubernetes cluster.

By default, the kubectl command interacts with this 'default' Namespace, but it can be changed to any other Namespace.

In this note i will show how to set the default Namespace in Kubernetes.

πŸ“– Continue Reading
🌐 Umount: Force – Target | Device is Busy

An umount command is used to unmount a device/partition by specifying the path to the directory where it has been mounted.

Sometimes, when you run the umount command you may receive the "target is busy" or "device is busy" errors indicating that there is some process that is using the mounted filesystem or the remote file server is not responding for some reason.

Luckily, it is possible to run the umount command forcefully and this short note shows how to do this safely.

πŸ“– Continue Reading
🌐 Jenkins: List All Jobs – Groovy Script

The easiest way to get a list of all Jenkins jobs is by executing an appropriate Groovy script using a Jenkins script console feature.

This note shows two examples of Groovy scripts for listing the Jenkins jobs.

The first script simply prints the list of all Jenkins jobs while the second one additionally lets you to identify how the last build of each job was triggered, e.g. manually by user, triggered by commit, by schedule etc.

πŸ“– Continue Reading
🌐 Linux: Find Files by Name & Grep Contents

The Linux find command can be used for searching files and directories and performing subsequent operations on them.

If you use the find command to recursively search for some files and then pipe the result to the grep command, by doing this you will actually parse the file paths/names but not their contents.

This short note shows how to recursively find files by name and grep their contents for some word or pattern.

πŸ“– Continue Reading
🌐 Kubectl: Get Pods on Node

A Pod is a group of one or more containers with shared storage, network and lifecycle and is the basic deployable unit in Kubernetes.

Each Pod is scheduled on the same Node, and remains there until termination or deletion.

In this note i will show how to get Pods running on a specific Node using the kubectl command.

πŸ“– Continue Reading
🌐 Kubernetes: Get Node Events

Kubernetes events are automatically created when other resources have state changes, errors or other messages that should be broadcasted to the system.

These events (logs) are very helpful for debugging issues in a Kubernetes cluster.

In this note i will show how to get events from a specific Node in the Kubernetes cluster using the kubectl command.

πŸ“– Continue Reading