Project

General

Profile

Bash tricks » History » Revision 5

Revision 4 (Alexis Jeandet, 30/03/2014 03:47 PM) → Revision 5/14 (Alexis Jeandet, 30/03/2014 03:48 PM)

{{>toc}} 

 h1. Bash tricks 

 h2. Get disk usage 

 <pre><code class="bash"> 
 df -h 
 </code></pre>  

 Will give you something like this: 

 <pre> 
 Sys. de fichiers         Taille Utilisé Dispo Uti% Monté sur 
 /dev/sde1                  110G      8,1G     97G     8% / 
 devtmpfs                   126G         0    126G     0% /dev 
 tmpfs                      126G         0    126G     0% /dev/shm 
 tmpfs                      126G      920K    126G     1% /run 
 tmpfs                      126G         0    126G     0% /sys/fs/cgroup 
 tmpfs                      126G      4,0K    126G     1% /tmp 
 /dev/mapper/ddf1_DATA2      15T      7,7G     14T     1% /home 
 </pre> 

 h2. Get CPU and RAM usage 

 <pre><code class="bash"> 
 htop 
 </code></pre>  

 Will give you something like this: 

 p=. !{width: 80%}htop.png(htop screenshot example)! 

 To get more information about htop see "here":http://htop.sourceforge.net/index.php?page=main 

 


 h2. Start a Job without a queue 

 All process started from ssh are terminated when you close the ssh connection, even if you fork them 
 (./app &). They are closed because when a process is closed the system send the SIGTERM signal 
 to all its children, it’s done to avoid zombies process on a machine. To keep your task alive when 
 you disconnect from ssh, you should use screen ("tutorial":http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/), it will block the SIGTERM signal. To 
 start your application with screen: 

 <pre><code class="bash"> 
 screen # to start screen 
 ./your_app     #to start your application or any other command 
              #type ’ Ctrl-A’ Ctrl −A’ d to leave screen with your application running in background 
 </code></pre>  

 To reconnect to your previous session: 

 <pre><code class="bash"> 
 screen -ls −ls      # to list running sessions 
 screen -r 33287.pts-36.bender −r 33287.pts−36.bender # to reconnect to 33287.pts-36.bender 33287.pts−36.bender session 
 exit # to close your screen session 
 </code></pre>