cron job to load a webpage?

Forum rules
Before you post please read this

cron job to load a webpage?

Postby bigjme on Sun Jan 12, 2014 1:34 pm

hi everyone, so i am new to the forums and would like to set up a basic cron job for storing values in a database.
what it needs to do is get a value from a daemon an then open a webpage passing on the value every minute.
so far this is what i have

Cron
Code: Select all
* * * * * root /bin/bash /usr/local/test


test
Code: Select all
#!/bin/bash
balance = $(yacoind getbalance)
wget -O - http://example.com/task.php?balance=$balance >/dev/null 2>&1


ok so i have put this together from bits of code i have found online but i dont know if the code is correct.
in short it needs to run the command "yacoind getbalance" which will return the balance from the program. it then needs to send that value to the server in the url string so the database can store it and do some other tasks like email me if the balance has more then before.

the php script is easy but as this is my first ever cron job i would like a little help. i dont want the output of the url storing anywhere and i dont want the output of the cron emailing to anyone.
can someone help me?

i am sorry if this sort of stuff has been covered a million times
Regards,
Jamie
bigjme
Level 1
Level 1
 
Posts: 4
Joined: Sun Jan 12, 2014 1:23 pm

Linux Mint is funded by ads and donations.
 

Re: cron job to load a webpage?

Postby perham on Sun Jan 12, 2014 2:41 pm

how often do you want it to send? for example if you want every 20 minutes it should be like this:

Code: Select all
*/20 * * * * /usr/local/test


since you want it in root's crontab, you should run
Code: Select all
sudo crontab -e


and put the above line inside. you also need to make /usr/local/test executable, so run this:

Code: Select all
sudo chmod +x /usr/local/test


and you're done.
AMD Phenom II X6 1090T 3.2GHz DDR3-1600 12GB ]LinuxMint 16 Cinnamon
Intel Pentium 4 540 3.2GHz DDR-400 2GB LinuxMint 16 Mate
Intel Pentium 4 1.5 GHz 512MB Debian Jessie LXDE
User avatar
perham
Level 3
Level 3
 
Posts: 118
Joined: Sat Dec 28, 2013 7:52 pm
Location: Belgium

Re: cron job to load a webpage?

Postby bigjme on Sun Jan 12, 2014 2:45 pm

I dont too much need it as root. I can get the values using any user it just needs to run. I want it to pole every minute as I want relatively fast updates on when I get an increase in balance
bigjme
Level 1
Level 1
 
Posts: 4
Joined: Sun Jan 12, 2014 1:23 pm

Re: cron job to load a webpage?

Postby perham on Sun Jan 12, 2014 2:46 pm

bigjme wrote:I dont too much need it as root. I can get the values using any user it just needs to run. I want it to pole every minute as I want relatively fast updates on when I get an increase in balance


so replace 20 with 1 and run crontab -e (without sudo)
AMD Phenom II X6 1090T 3.2GHz DDR3-1600 12GB ]LinuxMint 16 Cinnamon
Intel Pentium 4 540 3.2GHz DDR-400 2GB LinuxMint 16 Mate
Intel Pentium 4 1.5 GHz 512MB Debian Jessie LXDE
User avatar
perham
Level 3
Level 3
 
Posts: 118
Joined: Sat Dec 28, 2013 7:52 pm
Location: Belgium

Re: cron job to load a webpage?

Postby bigjme on Sun Jan 12, 2014 2:54 pm

wouldn't I just leave it as * as that should be every minute?

I was mainly asking to make sure that the $balance part for the variable was right
bigjme
Level 1
Level 1
 
Posts: 4
Joined: Sun Jan 12, 2014 1:23 pm

Re: cron job to load a webpage?

Postby perham on Sun Jan 12, 2014 2:55 pm

bigjme wrote:wouldn't I just leave it as * as that should be every minute?

I was mainly asking to make sure that the $balance part for the variable was right

then the title of the thread is misleading. have you tried running your script?
AMD Phenom II X6 1090T 3.2GHz DDR3-1600 12GB ]LinuxMint 16 Cinnamon
Intel Pentium 4 540 3.2GHz DDR-400 2GB LinuxMint 16 Mate
Intel Pentium 4 1.5 GHz 512MB Debian Jessie LXDE
User avatar
perham
Level 3
Level 3
 
Posts: 118
Joined: Sat Dec 28, 2013 7:52 pm
Location: Belgium

Re: cron job to load a webpage?

Postby bigjme on Sun Jan 12, 2014 2:57 pm

not yet in case something is wrong and messes things up
ok so I tried my command and it looks like the actual command I need to run is

Code: Select all
curl --data-binary '{"method":"getbalance","params":[1, 0, null],"id":"getbalance"}:' -H 'content-type: text/plain;' http://user:pass@localhost:8332/


this needs to be stored in the balance variable and then used in the url string for the webpage to load. this is all related to loading a webpage using a cron job, so sorry if it was misleading
bigjme
Level 1
Level 1
 
Posts: 4
Joined: Sun Jan 12, 2014 1:23 pm

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests