Author: Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

In the world of programming, efficiency is key. Automation is one of the most powerful tools in a developer’s toolkit, allowing for the seamless execution of tasks without manual intervention. For Python developers, one of the most accessible and effective methods to automate scripts is through Crontab, a time-based job scheduler in Unix-like operating systems. This article provides a comprehensive guide to scheduling Python scripts using Crontab, ensuring that your tasks are executed efficiently and reliably. Step 1: Writing Your Python Script Before scheduling a task, you need a Python script. Write your Python script to perform a specific task.…

Read More

Some of the tasks are required to run twice per day. You can use */12 in hours section to schedule a job to run at 12AM and 12PM daily. Sometimes you need to run crontab at different hours or minutes. In that case, you can define the hours like 09,17 etc. For example: 0 */12 * * * script.sh The above script will run at 12 AM (00:00:00) and 12 PM (12:00:00) every day. As you can see that using */12 executes cron exactly at 12AM and 12PM. But, sometimes you may need to run crontab at different times like…

Read More

Shell scripts are handy for automating tasks like backup databases, clearing log files, etc. You need to perform some tasks when the script finishes the execution. No matter at which stage the script is finished. For example, a script that clears the log files from the system. The script first checks the size of the log file, if the log file size is lower than the specified size, the script exits. In that case, you still want to run a block of code. To do this, we can use the trap command to catch the EXIT signal and execute a…

Read More

Question: How do I convert all the characters to the lowercase of a string in the bash shell script? In Linux, the tr command is used to translate, squeeze, and/or delete characters. So with the help of the tr command, you can convert the case of any character. You can do this quickly with a single-line command. You can use the following command to convert a string to lowercase. Here the command takes the standard input of a string and processes it. echo “Input string here” | tr ‘[:upper:]’ ‘[:lower:]’ Let’s discuss with an example. Example Let’s create a sample…

Read More

I recently created a new Ubuntu 22.04 LTS Linux virtual machine. When I attempted to set up the PostgreSQL server on it, I saw a warning message like the one shown below on the screen: Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). Even after the warning message appeared, I was able to continue working. The way in which GPG keys are stored has been updated by the Debian developers, using the apt and GnuPG (GPG2) utilities, enhancing system security. You will notice this issue with Ubuntu 22.04 and Debian 11 systems. The steps below will…

Read More

A collation is a set of rules that defines how to compare and sort character strings in a database server. In this tutorial, we are discussing an error faced during database restoration on another server. Let’s see the problem and solution to the issue faced recently: The Problem: During the migration of a WordPress application, I faced the following error with the restoration of the MySQL database. The collation id may differ based on the MySQL version. Error message: Error 1273 (HY000) at line 36 Unknown collation: ‘utf8mb4_unicode_520_ci’ Here you go with a solution. The Solution: After searching for the…

Read More

We can use the trap command to catch the error signal system by the system during script execution. Then you can execute a shell command or call a function. In this way, you can execute your custom script code on an error that occurred in a bash script. This can be helpful to revert any partial changes, close database connections, or email status to the concerned persons, etc. You can use trap commands with `ERR` signals like: trap ‘on_error_function’ ERR When an error is generated in a shell script, it will execute a function named ‘on_error_function’ of your shell script.…

Read More

Question – How do I list all the collections available in the MongoDB database? MongoDB is a NoSQL database, that stores documents in JSON format. A collection is an entity in MongoDB (ie similar to a table in RDBMS databases) that stores JSON documents. You can use one of the below options to list collections in a MongoDB database. Mongo Shell: You can use one of the following commands from Mongo Shell to list all available collections in the MongoDB database. Before running the below commands you must be connected with the target database using use database_name. show collections show…

Read More

MongoDB find() method is used to select documents from a specified collection. It also set the cursor position to the selected document. The default find() method gets the documents from the start of the collection. In some situations, we need to fetch the last record from a collection. Use the following query to get the last records from a MongoDB collection. db.collection.find().limit(1).sort({$natural:-1}) The above query provides the single last record only, You can also fetch the multiple records from the end of the MongoDB collection. You can set the number of records with limit() method as below: db.collection.find().limit(5).sort({$natural:-1}) Thanks, Hope…

Read More

Cron is a service that runs tasks at specified intervals in Unix/Linux systems. It’s commonly used for operational tasks like cleaning log files or backing up databases. But for our purposes, we can also use it to automate applications to perform some tasks at regular intervals. In this article, we will see how we can run a job cron job every 10 minutes, 20 minutes, or 30 minutes. Use the following timer options to schedule a job in crontab to run on specified intervals. Running a corn every 10 minutes

Running a corn every 20 minutes

Running a…

Read More