Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
1. try adding 2>&1 at the end of the lftp line.
It may be sending something to stderr that is not being captured.
2. When it runs from cron, is the path the same? Try explicitly setting the path, or calling lftp with the full path. ENV differences have cropped up as a cause for cron script issues often.
So when run under cron (ONLY under cron) the lftp line generates NO OUTPUT!
There is clearly something missing here. I can test a very similar case on my machine and it performs as expected, yet on yours it does not. We are missing something.
Let me suggest using >> rather than > to accumlate the log, otherwise it will be cleared and overwritten every 60 seconds.
Questions: the start script is really only one command. Why did you not put that one command directly into your crontab file?
Do you really mean to run this process once per minute, every single minute, forever? If the command takes over 60 seconds, you will stack processes with unfortunate results. One of those results may be trashing your log file (see suggestion above re: >> ).
I would use a more sophisticated script that would check only continue if no other copy was already running.
Have you considered setting up openssh and using rsync in mirror mode to serve the function without lftp?
- There are other commands in the script also. But to replicate the issue I have modified the script to remove anything that could be causing the problem. The script now is as shown in the original post. Just one line.
- I only run the script every one minute when I am trying to resolve the issue, and I am testing the script. It will normally run @daily. The command usually takes less than 25 seconds to complete.
- I have considered other options including rsync and wget. I really like lftp though and I would prefer to use that.
But the question remains, why would it not provide any output when run using cron? What's changing there?
On what system did you test it, and got the expected results? Was it raspbian? Could it be something in the configuration of cron on my raspberry pi's?
Distribution: K/Ubuntu 18.04-14.04, Scientific Linux 6.3-6.4, Android-x86, Pretty much all distros at one point...
Posts: 1,802
Rep:
As wpeckham indicated, it's probably the environment.
To give you a working example, I had a script to deactivate DPMS on a machine running KDE, that I had to run on a regular basis (KDE has a bug in terms of DPMS, that when it's turned off, it gets turned back on, and with terribly short default settings)...
The original script (just the line I was trying to run) was as follows:
When you use cron,... the scripts are kind of run in "Never-never-land," for lack of a better term. You need to tell output where to go, otherwise it doesn't get directed to anywhere. After all, your cron scripts aren't being run from the standard output, they are jut being run
Distribution: K/Ubuntu 18.04-14.04, Scientific Linux 6.3-6.4, Android-x86, Pretty much all distros at one point...
Posts: 1,802
Rep:
KDE has nothing to do with it (it was just why I needed to run the xset command). I wasn't suggesting that you use "env DISPLAY-:0," as that would just direct the output to the display (and besides, wouldn't you need to use the double ampersands, anyway?!). What I was trying to point out is that you have to direct the output to where you want it to go...
Are you trying to append a log file there??? In that case, shouldn't you be using the cat command to append to the log, and direct the output to that log file?!?!
I know you're trying to tell me something, and I'm really trying to understand what, but I don't think I do.
Isn't this ">" enough to write the output of the command to a log file? Do I also need to use "cat"? And if I do, then how? I know "cat" reads a file, not appends to it.
Check the $HOSTNAME variable under cron and in an interactive shell to see if they match, or if it is even SET under cron. Some systems it is, others not.
I know, reaching a bit, but if you shoot enough arrows into the air one MUST hit something that looks like a target SOMEDAY! ;-)
Either:
1. stop using environment variables that you have not set and that do not exist under cron by default, or
2. set them Explicitly In your script. If you set them in the first script, make sure to export them so that they will carry into the script it calls.
If you had a line
Code:
export HOSTNAME="wumpus.hunt.org"
in the script then the behavior would not change under cron due to the value of $HOSTNAME being missing.
As you can see from the script, the only variables used are $HOSTNAME and $emailaddress.
I receive the email so that variable works. What you are saying is that if I define $HOSTNAME in the script, I should be OK?
If I have to define the variable $HOSTNAME then I'm in trouble. I have 45 raspberry pi's and I will have to set the $HOSTNAME variable on each and every one of them.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.