Have you ever dreamed of having a Linux command that did that thing you wanted to do in 1 line? Or maybe you need to repeat a command with some specific parameters periodically and see the output on your console to check what is going on in a specific part of the system while recording the output in a log file?
No matter the specific scenario, at some point you will like to have your own custom Linux command if you are spending a considerable amount of time on Linux boxes repeating some tasks. Here is how you can create your own custom Linux command:
1- Create a file under “/username/bin” (don’t specify any extensions in your file name)
2- Below should be the first line of your script file
3- Add the command or commands you want to run in your script file. Example:
while true; do
dt=$(date '+%d/%m/%Y %H:%M:%S');
echo "Queried: $dt"
if [ -z "$2" ]
4- Change the mod of your file to make it an executable
chmod +x filename
5- Reload bashrc
Now you command should be working. The example command above can be used like this:
repeat "oc get nodes" 30
This example command will run “oc get nodes” every 30 seconds (I named my custom command file as “repeat“).
Hope this helps.