Wednesday, October 3, 2012

BASH: Plot graph with one line command using gnuplot

This is for a quick visual inspection of your job data output as XY plot. The XY data containing is read from the file data_input.dat

    1.00    0.00000
    2.00    0.74103
    3.00    0.79751
      ..     ....
      ..     ....

$ gnuplot
> plot "data_input.dat"

Now a scatter plot will pop up as a window. If you are logged into remote session with ssh, make sure you have forwarded the X. i.e.  logged in with -X flag

$ ssh -X yourhost

Change it to line plot by adding 'with lines'

$ gnuplot
> plot "data_input.dat" with lines

__________________________________________________________

Now for more advanced options:
1) To save the plot as png image:
add set terminal png, set output "plot.png"

-----------------------------------------------------------------------------
set terminal png
set output "plot.png"
plot "data_input.dat" with lines
-----------------------------------------------------------------------------
Now the plot will be saved as 'plot.png' into working directory.
You can open the image from terminal using  eog (eye of gnome)
$ eog plot.png

2) To label the X and Y and plot grid:
add set ylabel "RMS", set xlabel "Time" and set grid
-----------------------------------------------------------------------------
set terminal png
set output "plot.png"
set ylabel "RMS"
set xlabel "Time"
set grid
plot "data_input.dat" with lines
-----------------------------------------------------------------------------

3)  If you want to plot 1st and 5th column in your data_input.dat:
add 'using 1:5' in plot command
 

-----------------------------------------------------------------------------
set terminal png
set output "plot.png"
set ylabel "RMS"
set xlabel "Time"
set grid
plot "data_input.dat" using 1:5 with lines
-----------------------------------------------------------------------------

4) To plot two data series in the same plot and label each line:
add next series after a comma


-----------------------------------------------------------------------------
set terminal png
set output "plot.png"
set ylabel "RMS"
set xlabel "Time"
set grid
plot "data_input.dat" using 1:2 with lines title 'data-1',  "data_input.dat" using 1:5 with lines title 'data-5'
-----------------------------------------------------------------------------

 To plot many series, it's convenient to use the line continuation character, "\" .
-----------------------------------------------------------------------------
set terminal png
set output "plot.png"
set ylabel "RMS"
set xlabel "Time"
set grid
plot "data_input.dat" using 1:2 with lines title 'data-1', \
       "data_input.dat" using 1:3 with lines title 'data-3'  \
       "data_input.dat" using 1:5 with lines title 'data-5'  \
-----------------------------------------------------------------------------

5) Running it from a script

Put all these commands into a script and run if you have to run them several times

-----------------------------------------------------------------------------
#!/usr/bin/gnuplot
reset
set terminal png
set output "plot.png"
set ylabel "RMS"
set xlabel "Time"
set grid
plot "data_input.dat" using 1:2 with lines title 'data-1', \
       "data_input.dat" using 1:3 with lines title 'data-3'  \
       "data_input.dat" using 1:5 with lines title 'data-5'  \
-----------------------------------------------------------------------------

matplotlib is another even better option for advanced graph creation

More examples:
Gnuplot 4.2 Tutorial
http://www.duke.edu/~hpgavin/gnuplot.html

Plot your graphs with command line gnuplot » Linux by Examples
http://linux.byexamples.com/archives/487/plot-your-graphs-with-command-line-gnuplot/

Data visualization tools for Linux
http://www.ibm.com/developerworks/linux/library/l-datavistools/

Thursday, August 23, 2012

Log BASH command error and write the output to a file along with the STDOUT

BASH shell error (STDERR) is displayed on the screen by default.  For the following find command, all the output, including error is displayed on screen

find /var/lib/. -name “*.py”

bash$ find /var/lib/. -name "*.py*"
find: /var/lib/./zfs: Permission denied
find: /var/lib/./dav: Permission denied
find: /var/lib/./mlocate: Permission denied
find: /var/lib/./php/session: Permission denied
find: /var/lib/./ldap: Permission denied
find: /var/lib/./aide: Permission denied
find: /var/lib/./dovecot: Permission denied
find: /var/lib/./nvidia: Permission denied
find: /var/lib/./nfs/statd: Permission denied
find: /var/lib/./pgsql: Permission denied
find: /var/lib/./sss/pipes/private: Permission denied
find: /var/lib/./sss/db: Permission denied
find: /var/lib/./iptraf: Permission denied
/var/lib/./zope/bin/zopeservice.py
/var/lib/./zope/bin/zopeservice.pyo
/var/lib/./zope/bin/zopeservice.pyc
find: /var/lib/./imap: Permission denied
find: /var/lib/./mailman/archives/private: Permission denied
find: /var/lib/./dhcpv6: Permission denied


If the following command is used, it will only write out the ‘find’ result to the log file, not any error.

find /var/lib/. -name “*.py” > find_py.log

How can you log the error along with the output to a file so that you can read it later or from a remote session?


Follow the commands and output below


find /var/lib/. -name “*.py” > find_py.log 


[Only STDOUT written to a log file; (STDERR output to screen only) ]

bash$ find /var/lib/. -name "*.py*" > find_py.log
find: /var/lib/./zfs: Permission denied
find: /var/lib/./dav: Permission denied
find: /var/lib/./mlocate: Permission denied
find: /var/lib/./php/session: Permission denied
find: /var/lib/./ldap: Permission denied
find: /var/lib/./aide: Permission denied
find: /var/lib/./dovecot: Permission denied
find: /var/lib/./nvidia: Permission denied
find: /var/lib/./nfs/statd: Permission denied
find: /var/lib/./pgsql: Permission denied
find: /var/lib/./sss/pipes/private: Permission denied
find: /var/lib/./sss/db: Permission denied
find: /var/lib/./iptraf: Permission denied
find: /var/lib/./imap: Permission denied
find: /var/lib/./mailman/archives/private: Permission denied
find: /var/lib/./dhcpv6: Permission denied

bash$ cat find_py.log
/var/lib/./zope/bin/zopeservice.py
/var/lib/./zope/bin/zopeservice.pyo
/var/lib/./zope/bin/zopeservice.pyc



find /var/lib/. -name “*.py” 2> find_py.log


[Only STDERR written to a log file; (No STDERR output to screen; Only STDOUT output on screen)]

bash$ find /var/lib/. -name "*.py*" 2> find_py.log
/var/lib/./zope/bin/zopeservice.py
/var/lib/./zope/bin/zopeservice.pyo
/var/lib/./zope/bin/zopeservice.pyc

bash$ cat find_py.log
find: /var/lib/./zfs: Permission denied
find: /var/lib/./dav: Permission denied
find: /var/lib/./mlocate: Permission denied
find: /var/lib/./php/session: Permission denied
find: /var/lib/./ldap: Permission denied
find: /var/lib/./aide: Permission denied
find: /var/lib/./dovecot: Permission denied
find: /var/lib/./nvidia: Permission denied
find: /var/lib/./nfs/statd: Permission denied
find: /var/lib/./pgsql: Permission denied
find: /var/lib/./sss/pipes/private: Permission denied
find: /var/lib/./sss/db: Permission denied
find: /var/lib/./iptraf: Permission denied
find: /var/lib/./imap: Permission denied
find: /var/lib/./mailman/archives/private: Permission denied
find: /var/lib/./dhcpv6: Permission denied

find /var/lib/. -name “*.py” 2> find_py.log 1>&2 


STDOUT and STDERR written to a log file; (Nothing output to screen)

bash$ find /var/lib/. -name "*.py*" 2> find_py.log 1>&2

bash$ cat find_py.log
find: /var/lib/./zfs: Permission denied
find: /var/lib/./dav: Permission denied
find: /var/lib/./mlocate: Permission denied
find: /var/lib/./php/session: Permission denied
find: /var/lib/./ldap: Permission denied
find: /var/lib/./aide: Permission denied
find: /var/lib/./dovecot: Permission denied
find: /var/lib/./nvidia: Permission denied
find: /var/lib/./nfs/statd: Permission denied
find: /var/lib/./pgsql: Permission denied
find: /var/lib/./sss/pipes/private: Permission denied
find: /var/lib/./sss/db: Permission denied
find: /var/lib/./iptraf: Permission denied
/var/lib/./zope/bin/zopeservice.py
/var/lib/./zope/bin/zopeservice.pyo
/var/lib/./zope/bin/zopeservice.pyc
find: /var/lib/./imap: Permission denied
find: /var/lib/./mailman/archives/private: Permission denied
find: /var/lib/./dhcpv6: Permission denied



find /var/lib/. -name “*.py” 2>&1 | tee find_py_tee.log


STDOUT and STDERR written to a log file; (Also displayed on screen live while writing the log)

bash$ find /var/lib/. -name "*.py*" 2>&1 | tee find_py_tee.log
find: /var/lib/./zfs: Permission denied
find: /var/lib/./dav: Permission denied
find: /var/lib/./mlocate: Permission denied
find: /var/lib/./php/session: Permission denied
find: /var/lib/./ldap: Permission denied
find: /var/lib/./aide: Permission denied
find: /var/lib/./dovecot: Permission denied
find: /var/lib/./nvidia: Permission denied
find: /var/lib/./nfs/statd: Permission denied
find: /var/lib/./pgsql: Permission denied
find: /var/lib/./sss/pipes/private: Permission denied
find: /var/lib/./sss/db: Permission denied
find: /var/lib/./iptraf: Permission denied
/var/lib/./zope/bin/zopeservice.py
/var/lib/./zope/bin/zopeservice.pyo
/var/lib/./zope/bin/zopeservice.pyc
find: /var/lib/./imap: Permission denied
find: /var/lib/./mailman/archives/private: Permission denied
find: /var/lib/./dhcpv6: Permission denied

bash$ cat find_py_tee.log
find: /var/lib/./zfs: Permission denied
find: /var/lib/./dav: Permission denied
find: /var/lib/./mlocate: Permission denied
find: /var/lib/./php/session: Permission denied
find: /var/lib/./ldap: Permission denied
find: /var/lib/./aide: Permission denied
find: /var/lib/./dovecot: Permission denied
find: /var/lib/./nvidia: Permission denied
find: /var/lib/./nfs/statd: Permission denied
find: /var/lib/./pgsql: Permission denied
find: /var/lib/./sss/pipes/private: Permission denied
find: /var/lib/./sss/db: Permission denied
find: /var/lib/./iptraf: Permission denied
/var/lib/./zope/bin/zopeservice.py
/var/lib/./zope/bin/zopeservice.pyo
/var/lib/./zope/bin/zopeservice.pyc
find: /var/lib/./imap: Permission denied
find: /var/lib/./mailman/archives/private: Permission denied
find: /var/lib/./dhcpv6: Permission denied



The 2>&1 redirect STDERR to STDOUT.
This will record any errors to the logfile along with STDOUT.

Saturday, May 12, 2012

Dell Streak 5: USSD code problem fix for Gingerbread 2.3.3

hunderteins of XDA form has done an excellent job to fix the USSD code problem in Dell Streak 5 Gingerbread Android 2.3.3. TheManii put it easy for us to update the fix comfortably using StreakMod.  It's working perfect for me and you can try it if you want. If you want to fix, here's the detailed instruction on how you can fix it.


This tutorial assume you have Gingerbread installed in your DS. If you have already flashed streakmod, skip the first part. If you have rooted following my previous post, you may already have flashed StreakMod.


Requirements and downloads




  • Unzip to a folder; say C:\Fastboot+ADB



Process overview:
A) Enter fastboot mode and flash the streakmod custom recovery
B) Reboot to the streakmod recovery and select option 2 and then ‘update from update.zip’ to select update-USSDfix-2.zip





A) Flash the streakmod custom recovery
  • Connect  your DS to PC (You already installed drivers to it) and copy update-USSDfix-2.zip to the DS SD card.
  • Stop USB connection and power down DS (DS is still physically connected to the PC through the cable)
  • Press and hold down the camera button and then press the power button. Release the button when you see a white screen
  • Select Fast boot mode on the top right on your mobile (DS display will show FASTBOOT_MODE)
  • Now it’s time to do some DOS commands from your PC to communicate with DS through the connected USB cable.
  • On your PC, navigate to the path where you unzipped the fastboot tools.(C:\Fastboot+ADB). You have already copied the streakmod recovery (C:\Fastboot+ADB\Win32\recovery.img) to this folder. (see requirements)
  • Press Shift key and from right click menu open a DOS command window on that folder
  • Type  'fastboot -i 0x413c flash recovery recovery.img' without the quotes and hit enter. You can see that your DS screen shows the response.(By the way, you can copy paste the commands to the DOS prompt. Right click on DOS command and paste.)
  • Type 'fastboot -i 0x413c reboot' without the quotes and hit enter.  
B) Reboot to the streakmod recovery, select option 2 (update) and select ‘update from update.zip’ to select update-USSDfix-2.zip file.

  • On reboot, immediately go in recovery mode (hold both volume buttons while powering on). Don’t let it go to full system boot yet.
  • Select option 2: Update from update.pkg on sdcard. Now this would go to be the custom streakmod recovery. (See version number at lower bottom in yellow font. If not, you are not on StreakMod and you can't proceed) 
  • Select
  • update-USSDfix-2.zip
  • and proceed instructions to patch
  • Now the patching process will start and finish. On rebooting, your DS will regain the USSD power! Try your USSD code and see if it works. 
  • [Optional] Post your experience here if you feel like. :)
Thanks again to XDA geeks hunderteins, TheManii, DJ_Steve and the rest 
Reference