Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
What I'm trying to achieve is for cron to run a command every half hour, which runs a script located in /home/user/.scripts/ creatively called script. This script, as per my previous thread checks if a program is running, if it isn't, runs it.
In /home/user/.scripts/script ls -l shows
Code:
-rwxr-xr-x 1 user user 85 Jun 29 19:40 script
To me this says that it is indeed executable. I can run it using either sh script or ./script, not sure what the difference is.
crontab -l shows:
Code:
*/30 * * * * sh /home/user/.scripts/script
Which to me says that it should be run on every hour and half hour.
And sudo cat /var/log/syslog shows:
Code:
Jun 30 08:00:01 desktop /USR/SBIN/CRON[7660]: (user) CMD (sh /home/user/.scripts/script)
Jun 30 08:30:01 desktop /USR/SBIN/CRON[7676]: (user) CMD (sh /home/user/.scripts/script)
Jun 30 09:00:01 desktop /USR/SBIN/CRON[7745]: (user) CMD (sh /home/user/.scripts/script)
etc. which shows that cron is executing the commands. But it's not actually running when I check.
The script itself works fine if I run it from a command line. I can see that the cronjob is being run. But it isn't working. How do I get insight into what is occurring?
Two items -
1. you assume that "deluge" and "pkill" (or pgrep) is in the search path for the program. It won't work if they aren't.
2. (this is a bit of a nit and can be ignored) you assume that the process named "deluge" is actually the one you want... A process can have any name it wants - If you make a symbolic link to "ls" and name it deluge, then, when run, ls will be identified as "deluge".
Have you checked your local mail? cron will mail any output from a job to the local mail account, so any errors generated by the script will be mailed to you.
One more thing - does "deluge" require a GUI? If it does, then it will not necessarily be available - you might be logged out, and if you log in it may not be able to get the correct access key as it would have been cut off when you logged out...
That piece of code doesn't look correct. Try this instead:
Code:
#!/bin/bash
pgrep -f "deluge" 2>&1>/dev/null
if [[ "$?" -ne "0" ]]
then
deluge &
fi
I don't know what deluge does, and you might want to include the full path to the executable.
Hi,
Thanks for the idea. Unfortunately the script doesn't work and I don't know what you mean by 'the full path to the executable'. I type in deluge in the command line and it runs.
jpollard, I'm afraid I don't really understand what you've said. I didn't know I had local mail either. It does have a GUI, but the computer is always logged in.
I just want my computer to start deluge at boot, which sometimes it does, other times it doesn't. This is why I thought this script which runs every half hour would fix that. Check it's running, if not, start it.
Just a random idea I've just had, but can't find how to do it at the moment. If I set the script to start on boot, the I could have the script loop itself infinitely every 30 minutes.
Code:
#!/bin/bash
while :
do
pkill -0 -f "deluge" >& /dev/null
if [[ $? -eq 0 ]]; then
deluge &
fi
sleep 30m
done
Does the while, do, sleep and done elements of this script work? I appreciate that people think the script could be better, but I just want a very simple script that is basic, quick and works. I hope I never have to do any other scripting ever again, so I'm not too fussed if it's a bit ugly.
I just want my computer to start deluge at boot, which sometimes it does, other times it doesn't. This is why I thought this script which runs every half hour would fix that. Check it's running, if not, start it.
I think your approach to the actual problem (deluge starting/not starting at boot) is wrong.
You need to find out why deluge behaves this way. Putting a script in place that starts deluge if it isn't running makes the problem harder to trouble-shoot: Is deluge not starting or is the script faulty or possibly both.
Once you figure out why deluge behaves the way it does during boot you can tackle that and your problem is solved.
If deluge does start a gui: You cannot use cron to accomplish this (as already stated by jpollard) and I doubt it will start during the boot process.
EDIT: As a workaround you might use the ability of Desktop Managers (gnome/kde/etc) to start a program when you log in.
How do I tell why MATE appears to have forgotten to start Deluge?
This is what is used to start the program. 3 times out of four, Deluge starts with no problem. Occasionally it forgets to start deluge.
Then you have a different problem. If deluge requires a GUI to work, it will almost never work through a cron job as it does not have access to the GUI.
I tried adding the script to /etc/init.d/ which didn't work, and then I added it to /etc/network/if-up.d/ and now my computer won't boot. If I manage to fix this, please can someone just tell me how I can get the computer to run this script at startup in a how to style? I'm quite sick of guessing my way through it and to be honest it was inevitable that eventually I was going to break the computer.
Thanks
Last edited by NotAComputerGuy; 07-05-2013 at 02:48 PM.
I just had a look at the deluge web pages and noticed that this bittorrent-client has 2 parts: A daemon (deluged) and a user interface (deluge).
The part you are talking about is the user interface, which is a graphical interface. As stated before by jpollard and me: You cannot start this at boot or by using cron.
In post #6 you tell us that deluge sometimes works and sometimes it doesn't. I don't think a script will solve this problem, you'll need to figure out why deluge (and/or deluged) acts this way. I suspect that something is wrong with the setup and that is why you are having problems.
I cannot point you to anything specific (I have no experience whatsoever with bittorrent clients in general and deluge in specific). Do have a look at the documentation that is present on the deluge web site and maybe the forum on that site might be able to help you.
I think maybe we are using the same words to describe different things. The computer that this is running on automatically logs in for me, and therefore I want this to run once the computer is booted and therefore logged on.
If I press the power button on my computer, after it does it's thing, with no input from anyone, it will wait on the desktop, logged in ready for me to go. I open a terminal and type:
Code:
sh /home/user/.scripts/script
and the script runs and works fine. This is what I want the computer to do. Wait for it to log itself in, and then run that script.
Is this still an impossibility even with this further explanation?
EDIT: As a workaround you might use the ability of Desktop Managers (gnome/kde/etc) to start a program when you log in.
If that doesn't (always) work: Have a look at the log files. It is not clear why it sometimes doesn't work, so I cannot point you to a specific log file. I would start with the deluge(d) log files.
I don't know what you mean by 'the full path to the executable'. I type in deluge in the command line and it runs.
To get full path of app
Code:
$ which deluge
/usr/bin/deluge
Quote:
Originally Posted by NotAComputerGuy
I'm afraid I don't really understand what you've said. I didn't know I had local mail either.
To check for mail, just enter 'mail'
Code:
$ mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/madhu": 1 message 1 new
>N 1 root Tue Jul 9 15:40 18/643 "Did you check bootlog?"
&
Quote:
Originally Posted by NotAComputerGuy
I just want my computer to start deluge at boot, which sometimes it does, other times it doesn't. This is why I thought this script which runs every half hour would fix that. Check it's running, if not, start it.
If you are using GUI, then why dont you start program at startup in System -> Preferences -> Startup Application
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.