0

I would like to use a script that modifies iptables and that starts rtmpsuck as a deamon.

My current script is:

 #!/bin/bash

 function help_txt {
   package="enable-rtmpsuck"

   echo "$package - setup rtmpsuck to intercept rtmp streams and start rtmpsuck as a deamon"
   echo " "
   echo "sudo $package [options]"
   echo " "
   echo "options:"
   echo "-p, --path                specify download path (default is the current directory)"
   echo " "
   echo "Please note that this script needs root privileges to work."
 }


 if [ $# -eq 0 ]
 then
   path="$PWD"
 elif [ $# -eq 2 -a \( "$1" == "-p" -o "$1" == "--path" \) -a -d "$2" ]
 then
   path="$2"
 else
   help_txt
   exit 1
 fi

 if [[ "$(id -u)" == "0" ]]
 then
   cd "$path"
   echo "changed directory to: $path"
   iptables -t nat -A OUTPUT -p tcp --dport 1935 -m owner ! --uid-owner root  -j REDIRECT
   echo "redirect all rtmp traffic to rtmpsuck"
   setsid sudo rtmpsuck >/dev/null 2>&1 &
   PID="$!"
   echo "$PID" > /tmp/.rtmpsuck_pid
   echo "started rtmpsuck deamon"
 else
   help_txt
   exit 1
 fi

Everything works fine, but rtmpsuck is using 96% of the CPU if I start it like that. Is there any way to get its normal behavior that is near 0% usage of the CPU?

I'm using Linux Mint 17.1.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1861174
  • 507
  • 1
  • 5
  • 14
  • 2
    What is the command or set of commands you would run in the interactive shell that would yield this low CPU cost? – ShellFish Jan 14 '15 at 20:40
  • When I only use "sudo rtmpsuck" in a shell, it works just fine, but I do not need the terminal output, when I capture a rtmp stream. So I wanted to run this as a deamon with "setsid sudo rtmpsuck >/dev/null 2>&1 – user1861174 Jan 15 '15 at 01:13
  • What happens when you execute `sudo rtmpsuck >/dev/null 2>&1 $` in the command line? Have you tried to run a different command with `setsid`? - Alternatively you could use `fork`. – ShellFish Jan 15 '15 at 01:15
  • When I use "sudo rtmpsuck >/dev/null 2>&1", it works perfectly fine. I used "setsid nice -n19 ionice -c3 nocache pv -s 4000784052224 -q -L 1m '/dev/sdb' >/dev/null 2>&1 < /dev/null &" to constantly read from my external hard drive, so it does not go to sleep. As I understand it, in bash "setsid command &" is the way to go to do a fork. – user1861174 Jan 15 '15 at 16:02

0 Answers0