Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, July 21, 2015

Merge Multiple Files in Unix/Linux

What I found following examples are the quickest and kind of cleanest way to combine and aggregate few files to one separate file.

sed -n wfile.merge file1 file2
Or:
awk '{print > "file.merge"}' file1 file2
Or:
sh -c 'cat file1 file2 > file.merge'

Note: If you want to run the above on multiple file you can select all of the in one go for example all the txt file in the current directory:


sed -n wfile.merge *.txt

Tuesday, June 23, 2015

Supervisor in Ubuntu : commands to restart start and reload config file


Supervisord is a great daemon for managing application processes. However it does not have a reload option, and restart works different than we get used to. These command makes the following effects.
service supervisor restart
Restart supervisor service without making configuration changes available. It stops, and re-starts all managed applications.
supervisorctl restart <name>
Restart application without making configuration changes available. It stops, and re-starts the application.
If you create a new configuration. None of the commands above will make it available. If you want to apply your configuration changes in both existing and new configurations, start applications in new configurations, and re-start all managed applications, you should run:
service supervisor stop
service supervisor start
If you do not want to re-start all managed applications, but make your configuration changes available, use this command:
supervisorctl reread
This command only updates the changes. It does not restart any of the managed applications, even if their configuration has changed. New application configurations cannot be started, neither. (See the “update” command below)
supervisorctl update
Restarts the applications whose configuration has changed.
Note: After the update command, new application configurations becomes available to start, but do not start automatically until the supervisor service restarts or system reboots (even if autostart option is not disabled). In order to start new application, e.g app2, simply use the following command:
supervisorctl start app2
Posted on

Friday, June 20, 2014

Retrieve the system spec from command line in linux

Use this following commands for CPU and Memory:
#CPU-INFO
cat /proc/cpuinfo
#MEM-INFO
cat /proc/meminfo

Also during the boot process many  messages are written to the message buffer, which you can view using "dmesg". e.g. do this:

dmesg >~/dmesg.out


Also this shell script provides a brief info about the hardware spec:
http://www.pixelbeat.org/scripts/sysinfo

Monday, May 19, 2014

Linux and Unix screen command - options to start quickly

To begin, start screen by running  screen in the command line. the screen session will be created.
Ctrl a is the default modifier for screen. You'll prefix every command with it. 


  • Then to detach the screen session press  Ctrl a  + d 
  • to list the screen sessions screen -list 
  • to reattach to a screen session type screen -r session-number-from-list e.g: screen -r 2531

For more options use screen --help. 



Tuesday, March 25, 2014

Dvtm & Dtach - Alternative for Screen in linux

DVTM&DTACH is an alternative for popular screen command. Unlike GNU Screen and tmux, dvtm doesn’t allow you to disconnect and reattach to sessions. You’ll have to run dvtm with dtach to detach from and reattach to your sessions. it is a bit painful at the begining but when you have no other choice like me you use it. I receive this error "Login name too long -- sorry" when i use screen the reason is a bug that does not accept hostname more than 20 character. so here you go this is an alternative :

Installation

if you use fedora or redhat family:
sudo yum install dvtm dtach
if use Ubunto or debian:
sudo apt-get dvtm dtach



Getting Started

To begin, start dvtm run  dvtmin the command line 
Ctrl g is the default modifier for dvtm. You'll prefix every command with it. like ctrl+a in screen.
To change the default mod, run dvtm with the -m flag. IE: dvtm -m a, will set the modifier to Ctrl a

Basics

  • MOD c creates a new window.
  • MOD x will close it.
  • MOD j/k will switch between windows. Also, your mouse will work.
  • MOD #, where # is the window number, will move you to the appropriate window.
  • MOD q will exit dvtm.

Layout

  • MOD h/l will resize the window laterally.
  • MOD t will stack inactive windows vertically.
  • MOD b will stack inactive windows horizontally.
  • MOD g will stack windows in a grid.
  • MOD space toggles between layouts.
  • MOD . hides a window.
When I start a project, I'll open a few windows. Start and minimize my watch processes. Get to work.

Detach

dtach procedure is simple.
  1. dtach -A /tmp/sessionName -r winch dvtm will create and attach to a new session.
  2. Do work.
  3. Ctrl \ to detach from the current session.
  4. dtach -a /tmp/sessionName to reattach.

P.S: for the old version of linux, like fedora8 or Ubuntu tat does not have the repository you should manually install dvtm like below:
download the latest version of it:
git clone git://repo.or.cz/dvtm.git 
dvtm needs this library:

sudo yum install ncurses-devel

then build it:
cd dvtm-0.11
make
sudo install make

All Done!



Tuesday, March 4, 2014

SSH-Agent (ssh-add) on Cygwin

if you want to get rid of entering the password evry time you login to servers you should follow this post :

If you DON’T have a ~/.bash_profile (a file that gets executed every time you start cygwin):

touch ~/.bash_profile
chmod a+x ~/.bash_profile
Now that you have the file, add this to it:

SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
 eval `$SSHAGENT $SSHAGENTARGS`
 trap "kill $SSH_AGENT_PID" 0
fi
This will start up ssh-agent for each Cygwin shell you have open. Close your Cygwin shell (if one is open) and open a new one. Now type:

ssh-add ~/.ssh/id_rsa
[enter your password]
That 's it..you dont have to enter password anymore albeit for this window. every time you open a new window you need to do the last step to say the ssh-add to remember the password...