Script to run Transmission during certain time period

Want to share your OpenWrt / Gargoyle knowledge? Implemented a new feature? Let us know here.

Moderator: Moderators

Post Reply
mugre1975
Posts: 2
Joined: Fri May 01, 2015 4:05 pm

Script to run Transmission during certain time period

Post by mugre1975 »

Hello

This is my first post, I have a TL-WR1043ND router and started investigating about running transmission in my router. As the daemon ended up eating too much resources and eventually killing the router, I had to find a way to get it running during the nights, and to stop it and disable it during daytime.

The following script is what I've achieved, I leave it for whoever needs it hoping it will help you as it did to me, and please feel free to suggest any modifications you find suitable in order to make it better.

Have in mind that the variables Begin Time (bg) and End Time (et) can be altered to whatever time suits your needs, you just need to change it with the format "hhmm"

Code: Select all

#!/bin/sh /etc/rc.common

START=98
STOP=99

boot() {
	#Get time from system and store it in hr
	date +%T > date.log
	hr=$(tr -d ':' < date.log | cut -c1-4)
	rm date.log
	#Preset values Begin Time (bg) and End Time (et)
	bg=0130
	ed=0730
	ms='Running Transmission Daemon from $bg to $ed'
	#Check if current system time is not between bg and eg
	if [ $hr -lt $bg -o $hr -gt $ed ]; then
		#Stop Transmission Daemon and disable Transmission
		/etc/init.d/transmission stop
		/etc/init.d/transmission disable
	else
		#Enable Transmission and start Transmission Daemon
		/etc/init.d/transmission enable
		/etc/init.d/transmission start
		echo $ms
	fi
}

start() {
	date +%T > date.log
	hr=$(tr -d ':' < date.log | cut -c1-4)
	rm date.log
	bg=0130
	ed=0730
	ms='Running Transmission Daemon from $bg to $ed'
	if [ $hr -lt $bg -o $hr -gt $ed ]; then
		/etc/init.d/transmission stop
		/etc/init.d/transmission disable
	else
		/etc/init.d/transmission enable
		/etc/init.d/transmission start
		echo $ms
	fi
}

stop()	{
	/etc/init.d/transmission stop
	/etc/init.d/transmission disable
	echo 'End script'
}

ispyisail
Moderator
Posts: 5212
Joined: Mon Apr 06, 2009 3:15 am
Location: New Zealand

Re: Script to run Transmission during certain time period

Post by ispyisail »

+1

Post Reply