LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-30-2013, 03:55 AM   #1
NotAComputerGuy
Member
 
Registered: Jun 2012
Distribution: Linux Mint - Debian Edition
Posts: 349

Rep: Reputation: 13
Script not running through cronjob?


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?
 
Old 06-30-2013, 04:02 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Can you post the script that is being run?
 
Old 06-30-2013, 04:03 AM   #3
NotAComputerGuy
Member
 
Registered: Jun 2012
Distribution: Linux Mint - Debian Edition
Posts: 349

Original Poster
Rep: Reputation: 13
Of course!

Code:
#!/bin/bash
pkill -0 -f "deluge" >& /dev/null
if [[ $? -eq 0 ]]; then
    deluge
fi
 
Old 06-30-2013, 04:27 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 06-30-2013, 04:42 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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...

Last edited by jpollard; 06-30-2013 at 04:44 AM.
 
Old 06-30-2013, 05:37 AM   #6
NotAComputerGuy
Member
 
Registered: Jun 2012
Distribution: Linux Mint - Debian Edition
Posts: 349

Original Poster
Rep: Reputation: 13
Quote:
Originally Posted by druuna View Post
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.
 
Old 06-30-2013, 05:56 AM   #7
NotAComputerGuy
Member
 
Registered: Jun 2012
Distribution: Linux Mint - Debian Edition
Posts: 349

Original Poster
Rep: Reputation: 13
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.

Thanks
 
Old 06-30-2013, 06:09 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by NotAComputerGuy View Post
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.

Last edited by druuna; 06-30-2013 at 06:11 AM.
 
Old 06-30-2013, 03:25 PM   #9
NotAComputerGuy
Member
 
Registered: Jun 2012
Distribution: Linux Mint - Debian Edition
Posts: 349

Original Poster
Rep: Reputation: 13
How do I tell why MATE appears to have forgotten to start Deluge?

Quote:
Originally Posted by druuna View Post
EDIT: As a workaround you might use the ability of Desktop Managers (gnome/kde/etc) to start a program when you log in.
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.
 
Old 06-30-2013, 08:21 PM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by NotAComputerGuy View Post
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.
 
Old 07-05-2013, 02:46 PM   #11
NotAComputerGuy
Member
 
Registered: Jun 2012
Distribution: Linux Mint - Debian Edition
Posts: 349

Original Poster
Rep: Reputation: 13
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.
 
Old 07-06-2013, 02:33 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 07-09-2013, 04:10 AM   #13
NotAComputerGuy
Member
 
Registered: Jun 2012
Distribution: Linux Mint - Debian Edition
Posts: 349

Original Poster
Rep: Reputation: 13
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?
 
Old 07-09-2013, 04:16 AM   #14
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
As I mentioned earlier:
Quote:
Originally Posted by druuna View Post
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.
 
Old 07-09-2013, 05:15 AM   #15
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Quote:
Originally Posted by NotAComputerGuy View Post
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 View Post
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 View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cronjob - Shell Script Not Running rcrosoer Linux - General 5 05-22-2013 07:35 AM
[SOLVED] cronjob is running several times project.linux.proj Linux - Newbie 2 04-01-2013 03:15 AM
cronjob not running! user1221 Linux - Newbie 6 05-26-2009 05:08 AM
script not running in cronjob dningale Solaris / OpenSolaris 2 08-14-2008 12:27 AM
script expression not running in cronjob dningale Solaris / OpenSolaris 2 08-13-2008 12:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration