Buid different programs with sublime text:
Sublime text is one of the best IDE you can think of, using this you can have lots of build functionality to build your code from the IDE at the same time.
What all you have to do:
1. Install sublime text.
2. select "Tools" > "Build System" > "New Build System..."
And over write the:
{
"shell_cmd": "make"
}
with the following for each of the different language and save them with there own language name at front for your reference. Although you can give what ever name you want.
This will create the file at the following folder:
/home/<user>/.config/sublime-text-3/Packages/User
example for me:
/home/amit/.config/sublime-text-3/Packages/User
3. Following are the config file for each of the language:
3a: For Bash
File name: bash.sublime-build
{
"cmd" : ["$file"],
"selector" : "source.shell",
"shell" : "bash"
}
3b: For mysql
File name: mysql.sublime-build
{
"cmd": ["mysql", "-u", "root", "-pYourPassword", "-e", "source $file"],
"file_regex": "sql$",
"selector": "source.sql"
}
3c: For perl
File name: perl.sublime-build
{
"cmd": ["perl", "-w", "$file"],
"file_regex": "pl$",
"selector": "source.perl"
}
3d: For PHP
File name: php.sublime-build
{
"cmd": ["php", "$file"],
"file_regex": "php$",
"selector": "source.php"
}
On mac for go:
$ pwd
/Users/amund/Library/Application Support/Sublime Text 3/Packages/User
$ cat go.sublime-build
{
"cmd":["/usr/local/go/bin/go", "run", "$file"],
"file_regex": "go$",
"selector": "source.go"
}
4. Few Notes:
a.You can use ctrl-b to build and can see the output at the IDE.
b. Other languages are there by default.
c. I will suggest you to keep in Automatic mode, so that it can use use all the different language at the same time.
5. At the above config: "file_regex": "php$", mean the file end with php, so you might like to save the file with those names and then should try the build.
6. By default the bash script need to be executable permission, before doing the build at the bash script. What I did, I did a directory view of the IDE and created a small bash script that will change the file permission of the files inside a folder and keeping the bash script on those directory. [ chmod -R a+x /home/amit/Documents/bash ] and do a build of this script, when ever I add a bash script at the bash folder.
$ pwd
/home/amit/.config/sublime-text-3/Packages/User
$ l$ ls -1
bash.sublime-build
mysql.sublime-build
perl.sublime-build
php.sublime-build
Preferences.sublime-settings
Disclaimer: Its a collection from lots of other site(s) and few of my notes. I would also like to declare that I am not owning lots of its content. Please feel free to contact me directly if you want me to remove any of your content, that you don't want to share to other through this blog.
Monday, 30 June 2014
Saturday, 28 June 2014
vagrant
vagrant installation:
1. Install the virtual box.
2. Download the vagrant code from website and install the same.
3.
$ vagrant box add hashicorp/precise32 http://files.vagrantup.com/precise32.box
$ vagrant init hashicorp/precise32
$ vagrant up
4.$ vagrant box add hashicorp/precise32 http://files.vagrantup.com/precise32.box
==> box: Adding box 'hashicorp/precise32' (v0) for provider:
box: Downloading: http://files.vagrantup.com/precise32.box
==> box: Successfully added box 'hashicorp/precise32' (v0) for 'virtualbox'!
amit@laptop:~$ vagrant init hashicorp/precise32
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
amit@laptop:~$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: amit_default_1403959296506_47328
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 4.1
==> default: Mounting shared folders...
default: /vagrant => /home/amit
amit@laptop:~$
5: Now from few of the above point you can get that:
The virtual box is listening on port 2222 on 127.0.0.1 and default user is "vagrant" password is "vagrant".
You can create your PKI for this. [ if you see your virtual machine, you can see a vm is running. ]
6. How do I login: [ vagrant ssh ]
ssh -p 2222 vagrant@127.0.0.1 #password is vagrant. [ this is old way. ]
7. vagrant suspend [ saved current state of the instance. ]
8. vagrant resume [ resume a previously suspended instance. ]
9. vagrant halt [ to stop the vm instance ]
10. vagrant up [ power on the vm machine. ]
11. start from scratch:
a. vagrant destroy
b. vagrant up
12. vagrant ssh [ to ssh into the vagrant box. ]
##
$ vagrant --help
Usage: vagrant [options] <command> [<args>]
-v, --version Print the version and exit.
-h, --help Print this help.
Common commands:
box manages boxes: installation, removal, etc.
connect connect to a remotely shared Vagrant environment
destroy stops and deletes all traces of the vagrant machine
global-status outputs status Vagrant environments for this user
halt stops the vagrant machine
help shows the help for a subcommand
init initializes a new Vagrant environment by creating a Vagrantfile
login log in to Vagrant Cloud
package packages a running vagrant environment into a box
plugin manages plugins: install, uninstall, update, etc.
provision provisions the vagrant machine
rdp connects to machine via RDP
reload restarts vagrant machine, loads new Vagrantfile configuration
resume resume a suspended vagrant machine
share share your Vagrant environment with anyone in the world
ssh connects to machine via SSH
ssh-config outputs OpenSSH valid configuration to connect to the machine
status outputs status of the vagrant machine
suspend suspends the machine
up starts and provisions the vagrant environment
version prints current and latest Vagrant version
For help on any individual command run `vagrant COMMAND -h`
Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.
##
1. Install the virtual box.
2. Download the vagrant code from website and install the same.
3.
$ vagrant box add hashicorp/precise32 http://files.vagrantup.com/precise32.box
$ vagrant init hashicorp/precise32
$ vagrant up
4.$ vagrant box add hashicorp/precise32 http://files.vagrantup.com/precise32.box
==> box: Adding box 'hashicorp/precise32' (v0) for provider:
box: Downloading: http://files.vagrantup.com/precise32.box
==> box: Successfully added box 'hashicorp/precise32' (v0) for 'virtualbox'!
amit@laptop:~$ vagrant init hashicorp/precise32
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
amit@laptop:~$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: amit_default_1403959296506_47328
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 4.1
==> default: Mounting shared folders...
default: /vagrant => /home/amit
amit@laptop:~$
5: Now from few of the above point you can get that:
The virtual box is listening on port 2222 on 127.0.0.1 and default user is "vagrant" password is "vagrant".
You can create your PKI for this. [ if you see your virtual machine, you can see a vm is running. ]
6. How do I login: [ vagrant ssh ]
ssh -p 2222 vagrant@127.0.0.1 #password is vagrant. [ this is old way. ]
7. vagrant suspend [ saved current state of the instance. ]
8. vagrant resume [ resume a previously suspended instance. ]
9. vagrant halt [ to stop the vm instance ]
10. vagrant up [ power on the vm machine. ]
11. start from scratch:
a. vagrant destroy
b. vagrant up
12. vagrant ssh [ to ssh into the vagrant box. ]
##
$ vagrant --help
Usage: vagrant [options] <command> [<args>]
-v, --version Print the version and exit.
-h, --help Print this help.
Common commands:
box manages boxes: installation, removal, etc.
connect connect to a remotely shared Vagrant environment
destroy stops and deletes all traces of the vagrant machine
global-status outputs status Vagrant environments for this user
halt stops the vagrant machine
help shows the help for a subcommand
init initializes a new Vagrant environment by creating a Vagrantfile
login log in to Vagrant Cloud
package packages a running vagrant environment into a box
plugin manages plugins: install, uninstall, update, etc.
provision provisions the vagrant machine
rdp connects to machine via RDP
reload restarts vagrant machine, loads new Vagrantfile configuration
resume resume a suspended vagrant machine
share share your Vagrant environment with anyone in the world
ssh connects to machine via SSH
ssh-config outputs OpenSSH valid configuration to connect to the machine
status outputs status of the vagrant machine
suspend suspends the machine
up starts and provisions the vagrant environment
version prints current and latest Vagrant version
For help on any individual command run `vagrant COMMAND -h`
Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.
##
Wednesday, 25 June 2014
nagios service dependencies
Nagios service dependencies:
Some time we don't want to keep alerting for the child alert check which is dependent on another service:
Example:
we have a mysql slave running on host "db_slave_1" and it dependent on the mysql_master that is running on the "db_master".
But we don't want to get mysql slave alert if the mysql is not working on the db_master host.
To have this parent slave relationship we have "Nagios service dependency":
define servicedependency {
host_name db_master
service_description mysql_master
dependent_host_name db_slave_1
dependent_service_description db_slave_status
execution_failure_criteria w,u,c
notification_failure_criteria w,u,c
}
Few more example: for logical understanding:
define servicedependency {
host_name master_host
service_description master_service
dependent_host_name slave_host
dependent_service_description slave_service
execution_failure_criteria w,u,c
notification_failure_criteria w,u,c
}
Another example:
define servicedependency {
host_name ram_the_father's house
service_description ram_the_father
dependent_host_name ram_the_father's house
dependent_service_description kid
execution_failure_criteria w,u,c
notification_failure_criteria w,u,c
}
Further information:
http://nagios.sourceforge.net/docs/3_0/dependencies.html
http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html
Some time we don't want to keep alerting for the child alert check which is dependent on another service:
Example:
we have a mysql slave running on host "db_slave_1" and it dependent on the mysql_master that is running on the "db_master".
But we don't want to get mysql slave alert if the mysql is not working on the db_master host.
To have this parent slave relationship we have "Nagios service dependency":
define servicedependency {
host_name db_master
service_description mysql_master
dependent_host_name db_slave_1
dependent_service_description db_slave_status
execution_failure_criteria w,u,c
notification_failure_criteria w,u,c
}
Few more example: for logical understanding:
define servicedependency {
host_name master_host
service_description master_service
dependent_host_name slave_host
dependent_service_description slave_service
execution_failure_criteria w,u,c
notification_failure_criteria w,u,c
}
Another example:
define servicedependency {
host_name ram_the_father's house
service_description ram_the_father
dependent_host_name ram_the_father's house
dependent_service_description kid
execution_failure_criteria w,u,c
notification_failure_criteria w,u,c
}
Further information:
http://nagios.sourceforge.net/docs/3_0/dependencies.html
http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html
Tuesday, 17 June 2014
quick mysql master slave configuration
NOTE: I am using ubuntu as my OS with mysql 5.5.
On master server:
[1] sudo vi /etc/mysql/my.cnf
# under [mysqld] add the following line, considering you have the default lines:
log-bin = master-bin
log-bin-index = master-bin.index
server_id = 1
[2] # Update your bind-address so that any one can access the db. You can also update your firewall accordingly:
bind-address = 0.0.0.0 # NOTE: you can comment the bind-address line too.
[3] mysql> create user replicaiton_user
grand replication slave on *.*
to replication_user identified by 'your_password';
[4]: Restart the mysql: " sudo service mysql restart "
[ You can have a look at /var/log/mysql/error/log mean while if you face any issue. ]
Configuring SLAVE:
[1]: sudo vi /etc/mysql/my.cnf
# under [mysqld] add the following line, considering you have the default lines:
relay_log = slave-relay-bin
relay_log_index = slave-relay-bin.index
server-id = 2
[2] Can comment the bind-address = 127.0.0.1 [ so that your application can access the slave system as a read only access. ]
[3] sudo service mysql restart
[4] mysql> change master to
master_host = 'your_master_host',
master_port = 'port_number_where_master_db_is_running',
master_user = 'replication_user',
master_password = 'your_replication_user's_password'
[5] > start slave;
[6] > show slave status;
[7]: Any further issue, check: /var/log/mysql/error.log
On master server:
[1] sudo vi /etc/mysql/my.cnf
# under [mysqld] add the following line, considering you have the default lines:
log-bin = master-bin
log-bin-index = master-bin.index
server_id = 1
[2] # Update your bind-address so that any one can access the db. You can also update your firewall accordingly:
bind-address = 0.0.0.0 # NOTE: you can comment the bind-address line too.
[3] mysql> create user replicaiton_user
grand replication slave on *.*
to replication_user identified by 'your_password';
[4]: Restart the mysql: " sudo service mysql restart "
[ You can have a look at /var/log/mysql/error/log mean while if you face any issue. ]
Configuring SLAVE:
[1]: sudo vi /etc/mysql/my.cnf
# under [mysqld] add the following line, considering you have the default lines:
relay_log = slave-relay-bin
relay_log_index = slave-relay-bin.index
server-id = 2
[2] Can comment the bind-address = 127.0.0.1 [ so that your application can access the slave system as a read only access. ]
[3] sudo service mysql restart
[4] mysql> change master to
master_host = 'your_master_host',
master_port = 'port_number_where_master_db_is_running',
master_user = 'replication_user',
master_password = 'your_replication_user's_password'
[5] > start slave;
[6] > show slave status;
[7]: Any further issue, check: /var/log/mysql/error.log
Saturday, 7 June 2014
python regex example1
Task: read a file and print match:
#!/usr/bin/env python
import re
amFile = open('file_name', 'r')
amRe = re.compile('\d{1,5}\s\w+\s\w+\.') # -> your regex
for line in amFile:
amOut = re.findall(amRe,line)
if amOut > 0:
print (amOut)
amFile.close()
NOTE:
\d{1,5} : any digit from 1 digit to 5 digits => [0 to 99999 ]
\s : a single space
\w+ : any word at least 1 char or more.
\s : a single space again
\w+ : any word at least 1 char or more.
\. : end with a .
123 Main St. <= This will match in the above example.
##############################################
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression (PCRE, see
below). This is highly experimental and grep -P may warn of
unimplemented features.
grep -P '\d{1,5}' filename
ifconfig | grep -o -P '(\d+\.){3}\d+'
192.168.0.110
192.168.0.255
255.255.255.0
127.0.0.1
255.0.0.0
=============================================
##############################################
#!/usr/bin/env python
import re
amFile = open('file_name', 'r')
amRe = re.compile('\d{1,5}\s\w+\s\w+\.') # -> your regex
for line in amFile:
amOut = re.findall(amRe,line)
if amOut > 0:
print (amOut)
amFile.close()
NOTE:
\d{1,5} : any digit from 1 digit to 5 digits => [0 to 99999 ]
\s : a single space
\w+ : any word at least 1 char or more.
\s : a single space again
\w+ : any word at least 1 char or more.
\. : end with a .
123 Main St. <= This will match in the above example.
##############################################
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression (PCRE, see
below). This is highly experimental and grep -P may warn of
unimplemented features.
grep -P '\d{1,5}' filename
ifconfig | grep -o -P '(\d+\.){3}\d+'
192.168.0.110
192.168.0.255
255.255.255.0
127.0.0.1
255.0.0.0
=============================================
##############################################
Subscribe to:
Posts (Atom)