Cron with multiple commands
Started by
bonfield
, Jan 19 2012 02:15 PM
10 replies to this topic
#1
Posted 19 January 2012 - 02:15 PM
I'm trying to figure out how to get a cron set up for rss2email <http://www.allthings...com/rss2email/>
It runs fine from the command line. I login via SSH, cd to the directory -- cd .rss2email -- and run the command: ./r2e run.
It seems like the following cron should work, but it doesn't:
cd /home/<username>/.rss2email/ && ./r2e run >/dev/null 2>&1
I've tried both the ; and && syntax for multiple commands. Is it a cron syntax issue?
It runs fine from the command line. I login via SSH, cd to the directory -- cd .rss2email -- and run the command: ./r2e run.
It seems like the following cron should work, but it doesn't:
cd /home/<username>/.rss2email/ && ./r2e run >/dev/null 2>&1
I've tried both the ; and && syntax for multiple commands. Is it a cron syntax issue?
#2
Posted 19 January 2012 - 06:04 PM
Hi bonfield,
Sorry to hear about your troubles. I just had a quick look at this and noticed that the script is being run properly via cron. I watched the process this last time it ran and it seemed to complete properly. If something is not working properly when it's running it may be something with the script itself. If you open a support ticket with us and let us know exactly what the issues is that you are experiencing we can take a look for you. However, the script is being run by cron so I don't think it's an issue with the command you are using for the cron.
Sorry to hear about your troubles. I just had a quick look at this and noticed that the script is being run properly via cron. I watched the process this last time it ran and it seemed to complete properly. If something is not working properly when it's running it may be something with the script itself. If you open a support ticket with us and let us know exactly what the issues is that you are experiencing we can take a look for you. However, the script is being run by cron so I don't think it's an issue with the command you are using for the cron.
#3
Posted 19 January 2012 - 08:39 PM
Thanks for getting back to me so quickly. I didn't want to bother support on something where I was sure I was at fault. I'll open that ticket now.
#4
Posted 19 January 2012 - 08:47 PM
Why not just use the full path unless you need to actually be in that directory for some reason.
/home/<username>/.rss2email/r2e run >/dev/null 2>&1
Obsolescence is just a lack of imagination.
Sign up at ASO and enjoy friendly, quality hosting services. Use coupon code no2512 and save 15% or coupon code 2152on and take $5 off. Valid on both Shared Hosting and VPS plans.
Sign up at ASO and enjoy friendly, quality hosting services. Use coupon code no2512 and save 15% or coupon code 2152on and take $5 off. Valid on both Shared Hosting and VPS plans.
#5
Posted 25 January 2012 - 09:48 AM
NyteOwl, on 19 January 2012 - 08:47 PM, said:
Why not just use the full path unless you need to actually be in that directory for some reason.
/home/<username>/.rss2email/r2e run >/dev/null 2>&1
Thanks, NyteOwl, for this suggestion. Sorry for my delayed response.
Unfortunately, this doesn't seem to work. I believe it's because of the dot-slash donation needed to make ./r2e run execute.
I'm working with ASmallOrange's support to make sure this cron works. I'll report back once we get it up and running.
#6
Posted 25 January 2012 - 02:37 PM
"./" just means current directory.
To run a command that isn't in your path (run "echo $PATH" to find out what folders it searches in) then you need to call a command using a directory and a path, even if the directory part is just "./". If a simple script executes using "./command" then it will execute using "/full/path/to/command". The only time it won't is when the user trying to run it doesn't have execute/change directory permissions on a folder in /full/path/to (the "x" in "rwx").
The other problem, of course, is if your script uses the current working directory. In that case, executing it from another folder with the full path may have unexpected results, and it might not have important files where it expects them, but it will still run.
What happens if you remove " >/dev/null 2>&1" from your command? That is currently ditching all of the output, but Cron normally emails it to you. If it is failing then chances are it'll be telling you something useful in there (normally "file not found" or "permission denied").
To run a command that isn't in your path (run "echo $PATH" to find out what folders it searches in) then you need to call a command using a directory and a path, even if the directory part is just "./". If a simple script executes using "./command" then it will execute using "/full/path/to/command". The only time it won't is when the user trying to run it doesn't have execute/change directory permissions on a folder in /full/path/to (the "x" in "rwx").
The other problem, of course, is if your script uses the current working directory. In that case, executing it from another folder with the full path may have unexpected results, and it might not have important files where it expects them, but it will still run.
What happens if you remove " >/dev/null 2>&1" from your command? That is currently ditching all of the output, but Cron normally emails it to you. If it is failing then chances are it'll be telling you something useful in there (normally "file not found" or "permission denied").
The more information you provide, the better answer the community can give.
*** Sign up at ASO with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)
*** Sign up at ASO with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)
#7
Posted 26 January 2012 - 11:31 AM
Thanks for your help. I'm sorry to keep coming back for assistance, but none of the three solutions I've tried is working and I can't figure out why.
The first two crons below are taken from suggestions from this forum and from A Small Orange's customer support team, all of whom have been quick to respond and very helpful. Also, in the crons below, I've removed >/dev/null 2>&1 from the cron in order to capture errors (thanks, Massive Orange).
Though the crons aren't working, I can still login to my shell and
cd .rss2email
./r2e run
and the software works perfectly.
1. I'm running
15 * * * * /home/<username>/.rss2email/r2e
This is based on NyteOwl's suggestion above. This doesn't work from the command line or via cron. Here's the error I get:
E: insufficient args
rss2email: get RSS feeds emailed to you
http://rss2email.infogami.com
Usage:
new [emailaddress] (create new feedfile)
email newemailaddress (update default email)
run [--no-send] [num]
add feedurl [emailaddress]
list
reset
delete n
pause n
unpause n
opmlexport
opmlimport filename
2. I'm running
30 * * * * 'echo $SHELL' -c "/home/<username>/.rss2email/r2e run"
This is based on the suggestion from Massive Orange (above) and from A Small Orange customer support (via email). This doesn't work from the command line or via cron. Here's the error I get:
/bin/sh: echo $SHELL: command not found
3. I created the following script, which I named r2e_cron.sh:
#!/bin/bash
cd /home/<username>/.rss2email;
./r2e run
I set its permissions via chmod u+x and uploaded it to a new directory, scripts, which I added to my path using the following command:
export PATH="$PATH:~/scripts"
The cron command I'm using is:
/home/<username>/scripts/r2e_cron.sh
45 * * * * /home/<username>/scripts/r2e_cron.sh
It sort of works from the command line (some feeds are gathered but not all of them), but it doesn't work at all via cron, which is why the error below is confusing to me:
Fatal error: could not connect to mail server "mreko.asmallorange.com:465"
Check your config.py file to confirm that SMTP_SERVER and other mail server settings are configured properly
Again, this error might make sense, except I can still cd /home/<username>/.rss2email <enter> followed by ./r2e run <enter> and the software works perfectly.
The first two crons below are taken from suggestions from this forum and from A Small Orange's customer support team, all of whom have been quick to respond and very helpful. Also, in the crons below, I've removed >/dev/null 2>&1 from the cron in order to capture errors (thanks, Massive Orange).
Though the crons aren't working, I can still login to my shell and
cd .rss2email
./r2e run
and the software works perfectly.
1. I'm running
15 * * * * /home/<username>/.rss2email/r2e
This is based on NyteOwl's suggestion above. This doesn't work from the command line or via cron. Here's the error I get:
E: insufficient args
rss2email: get RSS feeds emailed to you
http://rss2email.infogami.com
Usage:
new [emailaddress] (create new feedfile)
email newemailaddress (update default email)
run [--no-send] [num]
add feedurl [emailaddress]
list
reset
delete n
pause n
unpause n
opmlexport
opmlimport filename
2. I'm running
30 * * * * 'echo $SHELL' -c "/home/<username>/.rss2email/r2e run"
This is based on the suggestion from Massive Orange (above) and from A Small Orange customer support (via email). This doesn't work from the command line or via cron. Here's the error I get:
/bin/sh: echo $SHELL: command not found
3. I created the following script, which I named r2e_cron.sh:
#!/bin/bash
cd /home/<username>/.rss2email;
./r2e run
I set its permissions via chmod u+x and uploaded it to a new directory, scripts, which I added to my path using the following command:
export PATH="$PATH:~/scripts"
The cron command I'm using is:
/home/<username>/scripts/r2e_cron.sh
45 * * * * /home/<username>/scripts/r2e_cron.sh
It sort of works from the command line (some feeds are gathered but not all of them), but it doesn't work at all via cron, which is why the error below is confusing to me:
Fatal error: could not connect to mail server "mreko.asmallorange.com:465"
Check your config.py file to confirm that SMTP_SERVER and other mail server settings are configured properly
Again, this error might make sense, except I can still cd /home/<username>/.rss2email <enter> followed by ./r2e run <enter> and the software works perfectly.
#8
Posted 28 January 2012 - 10:24 AM
Been a while since I had a shared account with cPanel, but it'd be worth checking which user your script is run as. Try editing your shell script to be:
The only other thing I can think of is paths. Cron can use a lot fewer environmental variables than normal (for security reasons) so it could be that it is failing because it doesn't have a command or import that it expects.
Oh and Massive Orange is my rank - the name's IBBoard
#!/bin/bash whoami > /home/<username>/whoami-cron.txt cd /home/<username>/.rss2email; ./r2e runthen check the whoami-cron.txt after the cron job runs.
The only other thing I can think of is paths. Cron can use a lot fewer environmental variables than normal (for security reasons) so it could be that it is failing because it doesn't have a command or import that it expects.
Oh and Massive Orange is my rank - the name's IBBoard
The more information you provide, the better answer the community can give.
*** Sign up at ASO with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)
*** Sign up at ASO with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)
#9
Posted 28 January 2012 - 12:57 PM
Yep. He's a massive orange. And all this time I thought he was just a fine grained pumpkin.
Obsolescence is just a lack of imagination.
Sign up at ASO and enjoy friendly, quality hosting services. Use coupon code no2512 and save 15% or coupon code 2152on and take $5 off. Valid on both Shared Hosting and VPS plans.
Sign up at ASO and enjoy friendly, quality hosting services. Use coupon code no2512 and save 15% or coupon code 2152on and take $5 off. Valid on both Shared Hosting and VPS plans.
#10
Posted 02 February 2012 - 04:26 PM
Sorry for the delay, and sorry for messing up your name, IBBoard. Here's what we got working. Big thanks to support at A Small Orange!
The cron:
30 * * * * $SHELL /home/disappea/.rss2email/r2e run
It turns out the issue was in how rss2email calls Python.
The the invocation line was...
python ./rss2email.py feeds.dat $*
...but had to be changed to...
/usr/local/bin/python2.6 ./rss2email.py feeds.dat $*
Here's the explanation I received:
"When you're logged in, the default python executable is python2.6, but when run as cron, it uses the system default which is python2.4. Since python2.6 is not in the folders designated by the $PATH variable, I had to specify the full path instead of python2.6...".
Again, major kudos to A Small Orange support. They're incredibly knowledgeable, responsive, and provide helpful explanations. I'm a very, very happy customer.
The cron:
30 * * * * $SHELL /home/disappea/.rss2email/r2e run
It turns out the issue was in how rss2email calls Python.
The the invocation line was...
python ./rss2email.py feeds.dat $*
...but had to be changed to...
/usr/local/bin/python2.6 ./rss2email.py feeds.dat $*
Here's the explanation I received:
"When you're logged in, the default python executable is python2.6, but when run as cron, it uses the system default which is python2.4. Since python2.6 is not in the folders designated by the $PATH variable, I had to specify the full path instead of python2.6...".
Again, major kudos to A Small Orange support. They're incredibly knowledgeable, responsive, and provide helpful explanations. I'm a very, very happy customer.
#11
Posted 04 February 2012 - 05:04 AM
I knew it'd end up being path issues in the end
I hadn't thought about different versions of Python, though.
The more information you provide, the better answer the community can give.
*** Sign up at ASO with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)
*** Sign up at ASO with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users
Sign In
Create Account








