[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

A guide to Linux commands to create a file using SSH, then set the CronJob to run the file on a ReadyNas running Linux

Posted on 2008-11-09
18
Medium Priority
?
1,259 Views
Last Modified: 2013-12-02
Hi Experts,

I really need some help in the Linux world.

I have a Netgear ReadyNas that operates a Linux OS.
I would like to set a CronJob for the Bittorent client on the box, however I don't know how to do it.
The scripts etc are in this forum
http://www.readynas.com/forum/viewtopic.php?f=36&t=16866&st=0&sk=t&sd=a&start=30

If you could tell me how, once I have logged into SSH to create the scripts and then set the CronJob I would really appreciate it.

Cheers

C
0
Comment
Question by:Craig Lambie
  • 12
  • 6
18 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22916034
to create script, you need to either copy with scp or sftp, or create using editor like vi.

OR

use

cat  "#!/bin/sh" > /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?auto_bandwidth_management="0"' >> /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?max_dl_rate="1024"' >> /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?max_ul_rate="1024"' >> /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?max_ul_rate_seed="1024"' >> /usr/share/bittorrent/bt-throttle-down.sh

similarly,you can do other scripts

for crontab:

crontab -l > mycron
cat '# Throttle the bittorrent manager according to time of day' >> mycron
cat '# Throttle down at 3:45pm, 15 minutes before ISP's peak usage period' >> mycron
cat '43 15 * * *     /usr/share/bittorrent/bt-throttle-down.sh' >> mycron
cat '# Throttle up at a quarter past midnight, 15 minutes after ISP's peak usage period' >> mycron
cat '15 00 * * *     /usr/share/bittorrent/bt-throttle-up.sh' >> mycron

crontab mycron
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22918547
Sorry, I should of mentioned....
I have no idea how to do anything in the world of Linux, so command by command is almost required to get me started at least.

Thanks
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22921419
you need to login to the system , then from command line, copy and paste commands given earlier:

cat  "#!/bin/sh" > /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?auto_bandwidth_management="0"' >> /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?max_dl_rate="1024"' >> /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?max_ul_rate="1024"' >> /usr/share/bittorrent/bt-throttle-down.sh
cat  '/usr/bin/wget -q -t 1 -O /dev/null http://localhost:8080/api/app-settings-set?max_ul_rate_seed="1024"' >> /usr/share/bittorrent/bt-throttle-down.sh


crontab -l > mycron
cat '# Throttle the bittorrent manager according to time of day' >> mycron
cat '# Throttle down at 3:45pm, 15 minutes before ISP's peak usage period' >> mycron
cat '43 15 * * *     /usr/share/bittorrent/bt-throttle-down.sh' >> mycron
cat '# Throttle up at a quarter past midnight, 15 minutes after ISP's peak usage period' >> mycron
cat '15 00 * * *     /usr/share/bittorrent/bt-throttle-up.sh' >> mycron


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Craig Lambie
ID: 22925872
Here is the results from copy and pasting

NASShared:~# cat  "#!/bin/sh" > /usr/share/bittorrent/bt-throttle-down.sh
-bash: !/bin/sh" > /usr/share/bittorrent/bt-throttle-down.sh: event not found
NASShared:~# /usr/share/bittorrent/bt-throttle-down.sh
-bash: /usr/share/bittorrent/bt-throttle-down.sh: No such file or directory
NASShared:~#  /usr/share/bittorrent/bt-throttle-down.sh
-bash: /usr/share/bittorrent/bt-throttle-down.sh: No such file or directory
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22927490
do you have the directory /usr/share/bittorrent already created? if not then you may create with

mkdir /usr/share/bittorrent
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22927589
ok, I have tried a couple of things now...

I think maybe the SSH program I am using doesn't work properly?
I am using this ZOC program for Windows to connect
http://www.emtec.com/zoc/index.html

Results:
NASShared:~# mkdir /usr/share/bittorrent
mkdir: cannot create directory `/usr/share/bittorrent': File exists
NASShared:~#
NASShared:~# cat  "#!/bin/sh" > /usr/share/bittorrent/bt-throttle-down.sh
-bash: !/bin/sh" > /usr/share/bittorrent/bt-throttle-down.sh: event not found
NASShared:~#
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22927593
I also tried to go into VI in this ZOC terminal and when I press ESC and then hit q it says

~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
'q' is not implemented                                                          
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22927643
if you are going to use vi, then the commands are

a to apend or i to insert
then put the text you want
then hit ESC key
then run :wq

If you face difficulty in using vi, then crate the file (text) on another system then scp or sftp it to the remote system
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22928061
ok, I have created the files in notepad and copied them into a share.

I then managed to use the
cd
ls
cp
commands to navigate around the SSH and get the files into the dir in question.

Now I went to add the next step of editting the CronTab I get this reply from the SSH
NASShared:/# crontab -l
no crontab for root
AND
NASShared:/# crontab -l > mycron
no crontab for root

So... do I need to create this somehow?
I was under the understanding that this just worked... but it doesn't seem to be so.?

C
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22928114
ok... now I have navigated to /etc/

then used vi, which I worked out I was missing the ":" in front of the q to make is quit correctly to edit this crontab file in the /etc/ dir

it now reads - Attached Code Snippet.

I hope this works... Will check it tonight and get back to you in the morning.

Cheers

C
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file.
# This file also has a username field, that none of the other crontabs do.
 
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
# m h dom mon dow user  command
25 6    * * *   root    test -e /usr/sbin/anacron || nice run-parts --report /et47 6    * * 7   root    test -e /usr/sbin/anacron || nice run-parts --report /et52 6    1 * *   root    test -e /usr/sbin/anacron || nice run-parts --report /et# Throttle the bittorrent manager according to time of day' >> mycron
# Throttle down at midday ' >> mycron
00 12 * * *     /usr/share/bittorrent/bt-throttle-down.sh' >> mycron
# Throttle up at 2am ISP's peak usage period' >> mycron
00 02 * * *     /usr/share/bittorrent/bt-throttle-up.sh' >> mycron
 
#
   

Open in new window

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22929946
it seams that you have a limited version of linux.

Since you did not have any crontab job for root already scheduled , then you could simply create mycron file which basically a temp file just to create the crontab jobs schedules
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22934827
ok,

so.... where should this file go?
Do I just simply put the cronjob info in it as per above snippet?

0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22945298
Ok...

I have been playing around with this and I have not got much of a result

NASShared:/etc# crontab -l
no crontab for root
NASShared:/etc# crontab -e
no crontab for root - using an empty one
editor: applet not found
crontab: "/usr/bin/editor" exited with status 1
NASShared:/etc# crontab -l
no crontab for root  

How would I set up the Cron Job?
I tried this command in /etc
vi mycron

edit the file, then ended with :wq
but the file didn't appear?

Should I create it somewhere else, then try to use it?
Where should it go?
How do I make it scheduled?

Thanks
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 400 total points
ID: 22946460
try

EDITOR=vi
export EDITOR

crontab -e

Then you add the schedules you want, then save and quit. If you do not know how to use vi, then you please create a temp file e.g. cronjobs (may be on some other system then copy to linux systtem) then run

crontab cronjobs

By the way you can add the job schedule to /etc/crontab but not both ways to avoid double work.
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22946616
Ok,
Did as you suggested, which made crontab -e work.

But then I put the crontab jobs in with vi, on getting out of the program with :wq (save) it suggested below.

So I went with the other option.
I with the other option... made a file, attached called cronjobs.txt
then changed it to just cronjobs

NASShared:/media# ls
BitTorrent  bt-throttle-down.sh  bt-throttle-up.sh  cronjobs  mycron
NASShared:/media# crontab cronjobs  

no errors reported, so will see what happens overnight

~
~
~
~
~
~
~
~
~
~
~
~
crontab: installing new crontab
"/tmp/crontab.XXXXacW1Z4":1: bad month
errors in crontab file, can't install.
Do you want to retry the same edit? n
crontab: edits left in /tmp/crontab.XXXXacW1Z4 

Open in new window

cronjobs.txt
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22956672
Ok... the cronjob doesn't appear to be running, so had a play with some commands, here are the results, any ideas?
Points Increased to accomodate long... long .. question
NASShared:~# /usr/share/bittorrent/bt-throttle-down.sh
-bash: /usr/share/bittorrent/bt-throttle-down.sh: Permission denied
NASShared:~# NASShared:~# crontab -l
-bash: NASShared:~#: command not found
NASShared:~# crontab -l
# Throttle down at midday ' >> mycron
00 12 * * *     /usr/share/bittorrent/bt-throttle-down.sh' >> mycron
# Throttle up at 2am ISP's peak usage period' >> mycron
00 02 * * *     /usr/share/bittorrent/bt-throttle-up.sh' >> mycron
 NASShared:~# cd /usr/share/bittorrent/
NASShared:/usr/share/bittorrent# ls
bin  bt-throttle-down.sh  bt-throttle-up.sh  dnacache  start_bt.sh  webui
NASShared:/usr/share/bittorrent# bt-throttle-down.sh
-bash: bt-throttle-down.sh: command not found     

Open in new window

0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 23026219
any ideas?
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 23118194
Do you have anymore to add to this job?
I would like to move on this, but I am not getting much response?

C
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question