Tuesday, June 4, 2013

Shell scripts to stop and Start your rtl_tcp Dongle (bash script) on Linux

Shell scripts to stop and Start your RTL Dongle (bash script)

Script to start rtl_tcp
1) Create a directory where you will store your scripts and where to save your process id.

mkdir sh   
cd sh  
mkdir pid

2) Use your favorite text editor (vi ...) and create a file (start_rtl.sh) with the following content
3) Change the pid file path to your directory as well as where the rtl_tcp excusable is.
4) Add port , ip if so required.
5) to find the path to rtl_tcp directory just use the command type rtl_tcp and you should get the path returned.

#!/bin/bash
#This program will write pid file
#pidfile
pidfile=/home/usersdir/sh/pid/rtl.pid
PROGRAM=/usr/local/bin/rtl_tcp
# We start app and create the pidfile
#Supported gain values for rtl_tcp (14): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0
        sudo $PROGRAM -g 42.0 &
        PID=$!
        echo $PID > "$pidfile"
        echo Program has started

Create a stop script wit your editor (stop_rtl.sh) in the same directory U created start script with the following content

#!/bin/bash
#This program will readthe pid file
#pidfile
pidfile=/home/userdir/sh/pid/rtl.pid
PROGRAM=/usr/local/bin/rtl_tcp
# We kill app and remove the pidfile``
        pid2kill=`cat $pidfile`
        kill -9 $pid2kill
        rm $pidfile

To run or stop the scripts just run sudo ./start_rtl.sh  or sudo ./stop_rtl.sh

Hope this helps.