Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cronjob issues with 18.04, it's not working, or i'm not.
#1
I use rsync every day. And in Arch and 16.04 i had it set to do it with cronjob. The last time I touched cron was in 2014. but i switched to 18.04 and set it up again. But today i checked my logs, and it has not given any output,,,,, ever. I am doing something wrong. but what.


sudo crontab -l
Code:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

# 31 17 * * * /bin/sh /etc/cron.daily/cron-rsync-4-bkup-sh
# 45 17 * * * /bin/bash /etc/cron.daily/cron-test.sh
00 18 * * * /bin/sh /etc/cron.daily/cron-test.sh
FLAT-BOX [c;crontab -l] ~                                                          18-09-08  5:49PM
eli:-->



The cron.daily folder looks like this
Code:
eli:--> cd /etc/cron.daily
FLAT-BOX [cd /etc/cron.daily] /etc/cron.daily                                      18-09-08  5:57PM
eli:--> l
0anacron    bsdmainutils          dpkg              man-db              ubuntu-advantage-tools
apport      cracklib-runtime      google-chrome     mlocate
apt-compat  cron-rsync-4-bkup-sh  google-earth-pro  passwd
aptitude    cron-test.sh          logrotate         popularity-contest
FLAT-BOX [l] /etc/cron.daily                                                       18-09-08  5:57PM
eli:-->
this is a new ubuntu install.

the test script i am trying to run
Code:
#!/bin/bash

zenity --info --width=200 --text="congratulations \nCron test passed"
 


here is the output log. but it only shows the one test run that i did.
Code:
# This is the backup log for the rsync script /home/eli/Scripts/bkup.sh
# It is Automatically called for by /etc/cron.daily/cron-rsync-4-bkup-sh
# Or Manually from /home/eli/Scripts/cron-rsync-4-bkup-sh

######## testing ##########

BACKUP success-Sat Apr 28 18:39:27 CDT 2018

###### end of test ########


what have i missed. i set permissions for all these to 755 so ,,,, uh.. help! please

I have forgotten something or 18.04 is broken. prolly me. lol

P.S.
i am pretty sure it is not the scripts, because they work perfectly when i run them manually.
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.
-
It is okay to not be able to answer a question,
however it should be a crime to not be able to question an answer.

@ArrowLinux
Reply
#2
I am a little tired right now, so I haven't read all your scripts,
but it might be something "simple":

I run a few scripts as cron jobs that use 'notify-send' to send me notifications.
These won't work unless the following command is executed after my Xserver starts,
because notify-send otherwise can not connect to the Xserver:
Code:
dbus-update-activation-environment DISPLAY XAUTHORITY

I don't know if this apllies for zenety,
but it is one of those configurations you do once and than just forget.


Because of that I always keep a file in which I document all my changes to the system.
It is quite handy and also a nice read if you find an old one from about a year ago Smile
My website - My git repos

"Things are only impossible until they’re not." - Captain Jean-Luc Picard
Reply
#3
(09-09-2018, 12:13 AM)leon.p Wrote: I am a little tired right now, so I haven't read all your scripts,
but it might be something "simple":

I run a few scripts as cron jobs that use 'notify-send' to send me notifications.
These won't work unless the following command is executed after my Xserver starts,
because notify-send otherwise can not connect to the Xserver:
Code:
dbus-update-activation-environment DISPLAY XAUTHORITY

I don't know if this apllies for zenety,
but it is one of those configurations you do once and than just forget.


Because of that I always keep a file in which I document all my changes to the system.
It is quite handy and also a nice read if you find an old one from about a year ago Smile

yeah i try to keep all the info in the script itself. but i guess i forgot that last time. because i am missing something. and like you said, it is probably something simple. something you do once and (forget)
thanks for the quick response.

i just found this video from Joe Collins called
"Linux Tip | How To Automate Tasks using Cron"

https://www.youtube.com/watch?v=bizxL_CA6J8

its almost 40 minuts long so let me get back to you as soon as it finnishes.
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.
-
It is okay to not be able to answer a question,
however it should be a crime to not be able to question an answer.

@ArrowLinux
Reply
#4
that was a pretty good video, it helped me figure out that the problem is for sure zenity. i ran $ echo "these words" > some_file.txt # in the script and it worked. then changed the same script to run a zenity popup and it failed.

so how do I get cron to run zenity script?
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.
-
It is okay to not be able to answer a question,
however it should be a crime to not be able to question an answer.

@ArrowLinux
Reply
#5
Have you considered where are your script stdout and stderr messages going?   We know cron will use syslog so, you can check the syslog by running this command:

grep -i 'cron.* mta ' /var/log/syslog* | head -8

if you see "(CRON) info (No MTA installed, discarding output)" messages, you do not have mail installed.  Remember, cron will send all std out and error to mail.   You can circumvent by using your own logging with your cronjob command as follows:

*/5 * *   *   *   /home/administrator/Cron_Test/simple_out >>/home/administrator/Cron_Test/simple_out.log 2>&1


In this cronjob example the std out and error from the simple_out script will be directed to the simple_out.log file.  Create the simple_out script with the following content:



#!/bin/bash


cd nowhere123.  # cause an error

echo "
ENV: 
`env`
"
#
### End of script



The crontab entry is an example and, you can substitute your working directory for the  /home/administrator/Cron_Test directory.  After the cronjob has ran the simple_out.log should contain the chdir() error as well has your environment variables.  Notice how few environment variables are set.   And yes, this is normal cron behavior.  I would suggest you set the appropriate environment variables in your script.   Furthermore, pay particular attention to the missing DISPLAY= environment variable.   Do you think zenity will run without it being set?


Reference:

man crontab
man 5 crontab
man 8 cron
Reply
#6
(09-09-2018, 03:55 AM)eliasw4u Wrote: so how do I get cron to run zenity script?

As I mentioned in my earlier comment, to do basically anything graphical from a cronjob,
you need to run the command I showed at startup (after the Xserver starts).

Code:
dbus-update-activation-environment DISPLAY XAUTHORITY
My website - My git repos

"Things are only impossible until they’re not." - Captain Jean-Luc Picard
Reply
#7
(09-09-2018, 07:38 PM)leon.p Wrote: As I mentioned in my earlier comment, to do basically anything graphical from a cronjob,
you need to run the command I showed at startup (after the Xserver starts).

Code:
dbus-update-activation-environment DISPLAY XAUTHORITY

Yeah i tried that. no affect. sorry i didn't let you know earlier.
It was worth trying though.

to give an update,
the script is good. i have tripple checked it. it works perfectly when ran manually.

But putting this in crontab

30 15 * * * /home/eli/Scripts/cron-rsync-4-bkup-sh >> /home/eli/Scripts/cron-rsync-4-bkup-sh.log 2>&1


Gave this output in the log

Code:
Unable to init server: Could not connect: Connection refused

(zenity:22488): Gtk-WARNING **: 15:26:01.749: cannot open display:

But I already know this, I just don't know why. So I am still lost.

deck_luck Thanks for that info, it helped me to confirm the issue. By the time of your post I was pretty sure what it was. now there is no question. though I still have not found the solution.
at least I know the problem.

P.S.
I am making myself a how-to-setup-cron.txt so this Never happens again.
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.
-
It is okay to not be able to answer a question,
however it should be a crime to not be able to question an answer.

@ArrowLinux
Reply
#8
A statement from my previous reply: Furthermore, pay particular attention to the missing DISPLAY= environment variable.   Do you think zenity will run without it being set?


Just like the example in my previous post create the following "simple_out" script and add it to your cron for testing:


#!/bin/bash


export DISPLAY=":0"

echo "
`date`
PWD: ${PWD}
HOME: ${HOME}
LOGNAME: ${LOGNAME}
DISPLAY: ${DISPLAY}

ENV:
`env`
"
notify-send --urgency=critical "eliasw4 notification: `date`"


#
### End of script




The crontab entry is an example and, you can substitute your working directory for the  /home/administrator/Cron_Test directory.  After the cronjob runs the simple_out.log will contain the standard out and error.  Also, you should see a gui notification pop up.  The notification is persistent until you click/clear it.
Reply
#9
the solution was to put


in top of  the script below the shebang
Code:
#!/bin/bash

export DISPLAY=:0

zenity --info --text="if you see this.the test passed"
the rest of the script here

and that worked.

i was trying to set the DISPLAY var in cron. but that didn't work because the script isn't a program (i assume). however setting  DISPLAY var in the script does work.

i also set cron SHELL to /bin/bash

this is my crontab in case anyone else has an issue with cron / zenity in the future

Code:
# Edit this file to introduce tasks to be run by cron.
#
# This is the Crontab setup and the basic layout.
#
#  _____________________ Minute  ( 0 -59 )
# |
# |  ________________________ Hour "24"  ( 0 - 23 )
# | |  
# | |  ___________________________ Day of Month  ( 1 - 31 )
# | | |
# | | |  ______________________________ Month  ( 1 - 12 )
# | | | |
# | | | |  _________________________________ day of week ( 0 - 6 ) - ( Sunday to Saturday )
# | | | | |
# | | | | |
# * * * * *  Command_To_Execute
#
# Language Rules
LC_MEASUREMENT=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LANG=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_TIME=en_US.UTF-8
# The Default PATH=/usr/bin:/bin    You might want to change that
PATH=/usr/local/bin:/usr/local/sbin/:/home/eli/.local/share/umake/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/l$
# The Default SHELL=/bin/sh   you might want to change that also
SHELL=/bin/bash
# Add tasks below
00 */12 * * * /home/eli/Scripts/cron-rsync-4-bkup-sh > /home/eli/Scripts/cron-rsync-4-bkupsh.log 2>&1
* * * * * /home/eli/Scripts/usrpthsh.sh
*/5 * * * * env DISPLAY=:0 zenity --info --text="if you see this.the test passed"
i have commented out the zenity test. of course.


thank you all very much for pointing me in the right direction. that saved me a lot of time. you guys are great.

kudos
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.
-
It is okay to not be able to answer a question,
however it should be a crime to not be able to question an answer.

@ArrowLinux
Reply
#10
Did you try reply #8 using the simple_out script with the export DISPLAY=":0" inside the script?   You do not have to have every zenity with "env DISPLAY=":0" prefix with your bash script.  Inside the bash script once the export DISPLAY=":0" is set all subsequent command will have access to the environment variable.    Just like the send-notifiy command in the example script.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)