If you have Mac system and created bash scripts so far, there is a fun feature on OS X that you can type
Or let's say you have a bash script that will take a lot of time and at the end of the script your want to hear
#osx #say #command #fun
say
command. say
will say the phrase:say hello channel users
Or let's say you have a bash script that will take a lot of time and at the end of the script your want to hear
operation done successfully
from your speaker:say operation done successfully
#osx #say #command #fun
There is a command in osX called
The great thing about this command is that you can open finder when you have traversed a long path and now you want it to have inside of finder. Go to the desired directory in your terminal using
it will open you finder. :)
#osx #open #command #fun #trick
open
that will open finder for you from within of your terminal.The great thing about this command is that you can open finder when you have traversed a long path and now you want it to have inside of finder. Go to the desired directory in your terminal using
cd
then use:open .
it will open you finder. :)
#osx #open #command #fun #trick
In
Now lets say you want to get count of files which is listed by
Now you shoud the count of files listed by the first command. This method of using 2 commands is
#linux #sysadmin #ls #wc #command #bash #terminal
ls
you can list files by using regex pattern as below:ls data.subtitle_*
*
is gready and list all the files that start with data.subtitle_
.Now lets say you want to get count of files which is listed by
ls
command. For that you can use wc -l
as follow:ls data.subtitle_* | wc -l
Now you shoud the count of files listed by the first command. This method of using 2 commands is
piping commands
, which is in fact separated by |
(pipe)#linux #sysadmin #ls #wc #command #bash #terminal
What are
#linux #grep #cat #zcat #command
cat
and zcat
commands and what is their differences?cat
is used to print the content of a file (in stdout or a file, etc). It's main usage is when you want to search something in the whole file like a log file:sudo cat /var/log/nginx/access.log | grep --color "SOMETHING TO SEARCH"
zcat
command on the other is used to get the content of a .gz
compressed text file like apache.log.1.gz
:sudo zcat /var/log/apache/apache.log.1.gz | grep --color "SOMETHING TO SEARCH"
NOTE:
grep command is used to search in a file. the symbol | (pipeline)
is used to send (pipe) first command result into the second command.#linux #grep #cat #zcat #command
Executing
In
If you are already running mysql, you can execute an SQL script file using the source command or \. command:
#mysql #execute #command #statement
MySQL
statements from a text file:In
MySQL
it is possible to put your SQL statements
in a file and then tell mysql to read its input from that file. To do so, create a text file text_file that contains the statements you wish to execute. Then invoke mysql as shown here:shell> mysql db_name < text_file
NOTE:
If you place a USE db_name
statement as the first statement in the file, it is unnecessary to specify the database name on the command line.If you are already running mysql, you can execute an SQL script file using the source command or \. command:
mysql> source file_name
#mysql #execute #command #statement
How to monitor network cards on
Ok for now we have added the plugin to nagios folder and ran some tests on target server's network interfaces. We need to add a command to
In brief it creates a new command called
Now we need to use this command in a service. We have to create a new service which will be used in our hosts configuration sections
Again in brief the service will be applied on hosts that have a variable section of
The final part is to add this service to your desired host. Go to
Add the service like below into your host:
You can go even further like me :) and add these data into
#icinga2 #icinga #service #host #command #nagios #interface #network
Icinga2
? (part-2)Ok for now we have added the plugin to nagios folder and ran some tests on target server's network interfaces. We need to add a command to
Icinga2
to use it in service section of Icinga2
. To create a new command create a new file in /etc/icinga2/conf.d/commands/check_nwc_command.conf
and with the following content:object CheckCommand "YOUR_COMMAND_NAME" {
import "plugin-check-command"
command = [ PluginDir + "/check_nwc_health", "--mode", "interface-usage" ]
arguments = {
"-H" = "$address$"
"-C" = "$community$"
"--name" = "$int$"
}
}
In brief it creates a new command called
YOUR_COMMAND_NAME
that calls the script check_nwc_health
with interface-usage
argument to get the bandwidth data.Now we need to use this command in a service. We have to create a new service which will be used in our hosts configuration sections
/etc/icinga2/conf.d/services/if_traffic.conf
:apply Service for (display_name => config in host.vars.int) {
import "generic-service"
check_command = "YOUR_COMMAND_NAME"
vars += config
assign where host.vars.int
}
Again in brief the service will be applied on hosts that have a variable section of
int
in their configuration that we will see a little bit later. YOUR_COMMAND_NAME
is the name that we have given in the first part when creating the command.The final part is to add this service to your desired host. Go to
/etc/icinga2/conf.d/hosts
and open the file which relates to your host. Host files content start with:object Host "host-54 (Infra)" {
Add the service like below into your host:
vars.int["YOUR DISPLAY NAME"] = {
int = "Device 1af4:0001 2"
community = "YOUR SERVER COMMUNITY STRING"
}
int
is the part that we give the interface name, this should be given from the output of list-interfaces
in part-1.You can go even further like me :) and add these data into
Grafana
dashboard to have a better understanding of what is happening around you.#icinga2 #icinga #service #host #command #nagios #interface #network
Click
is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It’s the “Command Line Interface Creation Kit”. It’s highly configurable but comes with sensible defaults out of the box.- http://click.pocoo.org/6/
#python #argparse #click #command_line_interface
https://unix.stackexchange.com/questions/31414/how-can-i-pass-a-command-line-argument-into-a-shell-script
#shell #argument #pass_argument #command_line #terminal #linux #bash #script
#shell #argument #pass_argument #command_line #terminal #linux #bash #script
Unix & Linux Stack Exchange
How can I pass a command line argument into a shell script?
I know that shell scripts just run commands as if they were executed in at the command prompt. I'd like to be able to run shell scripts as if they were functions... That is, taking an input value or
There are times you run a command in cronjob in a specific interval. Let's say you run that command every hour.
If your command copies a huge file, or you are doing a heavy task that may take longer than 1 hour sometimes, then you need
command in your arsenal.
Sample
See more samples here:
- http://manpages.ubuntu.com/manpages/xenial/man1/run-one.1.html
#linux #cronjob #command #run_one #runone
If your command copies a huge file, or you are doing a heavy task that may take longer than 1 hour sometimes, then you need
run-one
command in your arsenal.
run-one:
run just one instance at a time of some command and unique set of arguments (useful for cronjobs, eg)Sample
run-one
command:run-one rsync -azP $HOME $USER@example.com:/srv/backup
See more samples here:
- http://manpages.ubuntu.com/manpages/xenial/man1/run-one.1.html
#linux #cronjob #command #run_one #runone
Ubuntu
Ubuntu Manpage:
run-one - run just one instance at a time of some command and unique set of arguments
run-one - run just one instance at a time of some command and unique set of arguments