Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
(A bit wordy, I know.)
I have verified that this is executable and works from the commandline without any errors.
I have the following set up via crontab -e:
0,15,30,45 * * * * nice -n 19 $HOME/.xplanet/download_xplanet_cloudmap 5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh
The first line downloads cloudmaps for use with xplanet and works just fine (or appears to) and has done so for aeons.
However, nothing happens (or appears to) for the second line.
What is wrong here?
Many thanks and best wishes, Ranjan
On Wed, Oct 02, 2013 at 10:10:45AM -0500, Ranjan Maitra wrote:
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
Back when I did the BU Linux distribution, we had a similar script, which you can still get from
ftp://linst.bu.edu/yum/5.0/source/x86_64/SRPMS/kervercheck-1.0.4-bu50.1.src.rpm
You may find this useful.
I've been meaning to package this up for Fedora but have never gotten around to it. If someone else would like to, that would be awesome.
This script sends by e-mail, and therefore avoids what I think is the problem you have: notify-send attaches to the dbus message bus in your current X session, and jobs run distinct from that.
I haven't tried this, and it's been a long time since I've tried anything similar, but I think the steps here http://earlruby.org/2008/08/update-pidgin-status-using-cron/ should help -- it's someone trying to do basically the same thing. (There's an example for notify-send).
On 10/02/2013 08:10 AM, Ranjan Maitra issued this missive:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
(A bit wordy, I know.)
I have verified that this is executable and works from the commandline without any errors.
I have the following set up via crontab -e:
0,15,30,45 * * * * nice -n 19 $HOME/.xplanet/download_xplanet_cloudmap 5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh
The first line downloads cloudmaps for use with xplanet and works just fine (or appears to) and has done so for aeons.
However, nothing happens (or appears to) for the second line.
What is wrong here?
The most common problem I've seen is that cron jobs typically have very limited paths and the executables you're running (notify-send, uname) may not be in the path the cronjob has. For giggles, do "echo $PATH" as the user the cronjob will run as. Then build a cron job that echos cron's concept of the path:
#!/bin/bash echo $PATH >/tmp/pathecho.txt
and have cron run that once as the same user. Look at the data in /tmp/pathecho.txt and I'll bet you'll find its far more restricted than that of an interactive shell. To fix it, put in a
PATH="data from the echo $PATH command"
right after the "#!/bin/bash" line in your cron job. Since most of your commands are in /bin, you could do:
PATH=$PATH:/bin
and that would probably suffice (just making sure /bin is in the cron's path). ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 - - - - Grabel's Law: 2 is not equal to 3--not even for large values of 2. - ----------------------------------------------------------------------
On Wed, 2 Oct 2013 09:26:32 -0700 Rick Stevens ricks@alldigital.com wrote:
On 10/02/2013 08:10 AM, Ranjan Maitra issued this missive:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
(A bit wordy, I know.)
I have verified that this is executable and works from the commandline without any errors.
I have the following set up via crontab -e:
0,15,30,45 * * * * nice -n 19 $HOME/.xplanet/download_xplanet_cloudmap 5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh
The first line downloads cloudmaps for use with xplanet and works just fine (or appears to) and has done so for aeons.
However, nothing happens (or appears to) for the second line.
What is wrong here?
The most common problem I've seen is that cron jobs typically have very limited paths and the executables you're running (notify-send, uname) may not be in the path the cronjob has. For giggles, do "echo $PATH" as the user the cronjob will run as. Then build a cron job that echos cron's concept of the path:
#!/bin/bash echo $PATH >/tmp/pathecho.txt
and have cron run that once as the same user. Look at the data in /tmp/pathecho.txt and I'll bet you'll find its far more restricted than that of an interactive shell.
I tried this: here is what I got --
$ echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/home/user/bin
$ cat /tmp/pathecho.txt /usr/bin:/bin
Clearly more restrictive as you suggest.
However, what I do not understand is why this does not "work" though. I do not understand because notify-send is in /usr/bin as well as in /bin:
$ which notify-send notify-send is /bin/notify-send notify-send is /usr/bin/notify-send
Both appear to be in the path. So where is the problem?
I will also try the suggestions in the references in Matthew Miller's response now.
Many thanks, Ranjan
To fix it, put in a
PATH="data from the echo $PATH command"
right after the "#!/bin/bash" line in your cron job. Since most of your commands are in /bin, you could do:
PATH=$PATH:/bin
and that would probably suffice (just making sure /bin is in the cron's path).
On 10/02/2013 01:06 PM, Ranjan Maitra issued this missive:
On Wed, 2 Oct 2013 09:26:32 -0700 Rick Stevens ricks@alldigital.com wrote:
On 10/02/2013 08:10 AM, Ranjan Maitra issued this missive:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
(A bit wordy, I know.)
I have verified that this is executable and works from the commandline without any errors.
I have the following set up via crontab -e:
0,15,30,45 * * * * nice -n 19 $HOME/.xplanet/download_xplanet_cloudmap 5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh
The first line downloads cloudmaps for use with xplanet and works just fine (or appears to) and has done so for aeons.
However, nothing happens (or appears to) for the second line.
What is wrong here?
The most common problem I've seen is that cron jobs typically have very limited paths and the executables you're running (notify-send, uname) may not be in the path the cronjob has. For giggles, do "echo $PATH" as the user the cronjob will run as. Then build a cron job that echos cron's concept of the path:
#!/bin/bash echo $PATH >/tmp/pathecho.txt
and have cron run that once as the same user. Look at the data in /tmp/pathecho.txt and I'll bet you'll find its far more restricted than that of an interactive shell.
I tried this: here is what I got --
$ echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/home/user/bin
$ cat /tmp/pathecho.txt /usr/bin:/bin
Clearly more restrictive as you suggest.
However, what I do not understand is why this does not "work" though. I do not understand because notify-send is in /usr/bin as well as in /bin:
$ which notify-send notify-send is /bin/notify-send notify-send is /usr/bin/notify-send
Both appear to be in the path. So where is the problem?
I will also try the suggestions in the references in Matthew Miller's response now.
You could try adding a "set -x" after the shebang line:
#!/bin/bash set -x
That tells bash to print out every expansion. Then change your cron entry to have a ">/tmp/test.txt 2>&1" at the end:
5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh >/tmp/test.txt 2>&1
Let the script run, then examine the /tmp/test.txt file to see what bash doesn't like. Don't forget to remove the "set -x" from the script and the ">... 2>&1" stuff from the crontab entry when you're done. Odds are it's a path issue or something that isn't expanding as you think it would because it's not an interactive shell running the script. ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 - - - - He who laughs last thinks slowest. - ----------------------------------------------------------------------
On Wed, 2 Oct 2013 13:34:36 -0700 Rick Stevens ricks@alldigital.com wrote:
On 10/02/2013 01:06 PM, Ranjan Maitra issued this missive:
On Wed, 2 Oct 2013 09:26:32 -0700 Rick Stevens ricks@alldigital.com wrote:
On 10/02/2013 08:10 AM, Ranjan Maitra issued this missive:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
(A bit wordy, I know.)
I have verified that this is executable and works from the commandline without any errors.
I have the following set up via crontab -e:
0,15,30,45 * * * * nice -n 19 $HOME/.xplanet/download_xplanet_cloudmap 5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh
The first line downloads cloudmaps for use with xplanet and works just fine (or appears to) and has done so for aeons.
However, nothing happens (or appears to) for the second line.
What is wrong here?
The most common problem I've seen is that cron jobs typically have very limited paths and the executables you're running (notify-send, uname) may not be in the path the cronjob has. For giggles, do "echo $PATH" as the user the cronjob will run as. Then build a cron job that echos cron's concept of the path:
#!/bin/bash echo $PATH >/tmp/pathecho.txt
and have cron run that once as the same user. Look at the data in /tmp/pathecho.txt and I'll bet you'll find its far more restricted than that of an interactive shell.
I tried this: here is what I got --
$ echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/home/user/bin
$ cat /tmp/pathecho.txt /usr/bin:/bin
Clearly more restrictive as you suggest.
However, what I do not understand is why this does not "work" though. I do not understand because notify-send is in /usr/bin as well as in /bin:
$ which notify-send notify-send is /bin/notify-send notify-send is /usr/bin/notify-send
Both appear to be in the path. So where is the problem?
I will also try the suggestions in the references in Matthew Miller's response now.
You could try adding a "set -x" after the shebang line:
#!/bin/bash set -x
That tells bash to print out every expansion. Then change your cron entry to have a ">/tmp/test.txt 2>&1" at the end:
5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh >/tmp/test.txt 2>&1
Let the script run, then examine the /tmp/test.txt file to see what bash doesn't like. Don't forget to remove the "set -x" from the script and the ">... 2>&1" stuff from the crontab entry when you're done. Odds are it's a path issue or something that isn't expanding as you think it would because it's not an interactive shell running the script.
Here is what I get:
$ more /tmp/test.txt ++ tail -n1 ++ rpm -q kernel ++ sed -e s/kernel-// + latestkernel=3.11.2-201.fc19.i686 + grep -qv 3.11.2-201.fc19.i686 + uname -a ++ uname -r + notify-send 'Kernel UPDATE on subarnarekha.stat.iastate.edu: Running Kernel is 3.11.1-200.fc19.i686 but latest installed rpm is 3.11.2-201.fc19.i686; REBOOT r equired'
I also tried explicitly putting in /usr/bin/notify-send (hardcoding it in) to the original code, but no effect.
THanks, Ranjan
____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!
On 10/02/2013 02:27 PM, Ranjan Maitra issued this missive:
On Wed, 2 Oct 2013 13:34:36 -0700 Rick Stevens ricks@alldigital.com wrote:
On 10/02/2013 01:06 PM, Ranjan Maitra issued this missive:
On Wed, 2 Oct 2013 09:26:32 -0700 Rick Stevens ricks@alldigital.com wrote:
On 10/02/2013 08:10 AM, Ranjan Maitra issued this missive:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
(A bit wordy, I know.)
I have verified that this is executable and works from the commandline without any errors.
I have the following set up via crontab -e:
0,15,30,45 * * * * nice -n 19 $HOME/.xplanet/download_xplanet_cloudmap 5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh
The first line downloads cloudmaps for use with xplanet and works just fine (or appears to) and has done so for aeons.
However, nothing happens (or appears to) for the second line.
What is wrong here?
The most common problem I've seen is that cron jobs typically have very limited paths and the executables you're running (notify-send, uname) may not be in the path the cronjob has. For giggles, do "echo $PATH" as the user the cronjob will run as. Then build a cron job that echos cron's concept of the path:
#!/bin/bash echo $PATH >/tmp/pathecho.txt
and have cron run that once as the same user. Look at the data in /tmp/pathecho.txt and I'll bet you'll find its far more restricted than that of an interactive shell.
I tried this: here is what I got --
$ echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/home/user/bin
$ cat /tmp/pathecho.txt /usr/bin:/bin
Clearly more restrictive as you suggest.
However, what I do not understand is why this does not "work" though. I do not understand because notify-send is in /usr/bin as well as in /bin:
$ which notify-send notify-send is /bin/notify-send notify-send is /usr/bin/notify-send
Both appear to be in the path. So where is the problem?
I will also try the suggestions in the references in Matthew Miller's response now.
You could try adding a "set -x" after the shebang line:
#!/bin/bash set -x
That tells bash to print out every expansion. Then change your cron entry to have a ">/tmp/test.txt 2>&1" at the end:
5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh >/tmp/test.txt 2>&1
Let the script run, then examine the /tmp/test.txt file to see what bash doesn't like. Don't forget to remove the "set -x" from the script and the ">... 2>&1" stuff from the crontab entry when you're done. Odds are it's a path issue or something that isn't expanding as you think it would because it's not an interactive shell running the script.
Here is what I get:
$ more /tmp/test.txt ++ tail -n1 ++ rpm -q kernel ++ sed -e s/kernel-//
- latestkernel=3.11.2-201.fc19.i686
- grep -qv 3.11.2-201.fc19.i686
- uname -a
++ uname -r
- notify-send 'Kernel UPDATE on subarnarekha.stat.iastate.edu: Running
Kernel is 3.11.1-200.fc19.i686 but latest installed rpm is 3.11.2-201.fc19.i686; REBOOT r equired'
I also tried explicitly putting in /usr/bin/notify-send (hardcoding it in) to the original code, but no effect.
Ok, so it looks like there's nothing wrong in the script so you can remove the "set -x" from the script and the ">/tmp/test.txt 2>&1" from the crontab.
My guess is that the cron doesn't know that there is a GUI running and so notify-send doesn't know where to send the message. I've seen some stuff regarding this in one of the Ubuntu forums. Have a look at this:
http://askubuntu.com/questions/298608/notify-send-doesnt-work-from-crontab
In particular, look at the second and third answers (from danatela and krlmlr) and combine them (from danatela's answer to find who's logged in on the GUI and krlmlr's answer to set the DBUS_SESSION_BUS_ADDRESS for that user). ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 - - - - "I understand Windows 2000 has a Y2K problem." - ----------------------------------------------------------------------
On 02.10.2013 22:06, Ranjan Maitra wrote: …
However, what I do not understand is why this does not "work" though. I do not understand because notify-send is in /usr/bin as well as in /bin:
$ which notify-send notify-send is /bin/notify-send notify-send is /usr/bin/notify-send
Both appear to be in the path. So where is the problem?
poma
On Thu, 3 Oct 2013 02:17:09 +0200 poma pomidorabelisima@gmail.com wrote:
On 02.10.2013 22:06, Ranjan Maitra wrote: …
However, what I do not understand is why this does not "work" though. I do not understand because notify-send is in /usr/bin as well as in /bin:
$ which notify-send notify-send is /bin/notify-send notify-send is /usr/bin/notify-send
Both appear to be in the path. So where is the problem?
Thanks! But this does not "work" either. Here is what I tried in my crontab -e:
0 * * * * maitra DISPLAY=:0.0 $HOME/scripts/yum/check-kernel.sh
(maitra is my username).
Here is how I changed my check-kernel.sh, though I am not sure if there was a problem with the earlier one....
$more check-kernel.sh
#!/bin/bash # from http://goo.gl/Mqq6UP
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: " \ "<b><i>Running</i></b> kernel is <b><i>$(uname -r | awk '{gsub(/*PAE/,""); print}')</i></b> but <b>latest</b> <b><u>installed</u></b> is <b><u>${latestkernel}</u></b> required <b><u>REBOOT</u></b>" fi;
How do you get yours to work?
(Works fine from the commandline, of course.) Btw, FWIW, I am using dunst.
Many thanks, Ranjan
____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium
On Wed, Oct 02, 2013 at 07:55:51PM -0500, Ranjan Maitra wrote:
0 * * * * maitra DISPLAY=:0.0 $HOME/scripts/yum/check-kernel.sh
Did you try the things in the blog post I'd linked to? As I said in my previous method, notify-send needs to talk to your dbus session, and it can't get that from inside cron.
http://earlruby.org/2008/08/update-pidgin-status-using-cron/
has a way of working around that.
On Wed, 2 Oct 2013 21:38:26 -0400 Matthew Miller mattdm@fedoraproject.org wrote:
On Wed, Oct 02, 2013 at 07:55:51PM -0500, Ranjan Maitra wrote:
0 * * * * maitra DISPLAY=:0.0 $HOME/scripts/yum/check-kernel.sh
Did you try the things in the blog post I'd linked to? As I said in my previous method, notify-send needs to talk to your dbus session, and it can't get that from inside cron.
http://earlruby.org/2008/08/update-pidgin-status-using-cron/
has a way of working around that.
Sorry, I was going to get to this, but wanted to try the other quicker-implemented suggestions also. Now that there is a sort of workaround there, I will look into implementing this. (This looks more elegant to me: maybe it is no different from the other solution.)
Thanks again! Ranjan
-- Matthew Miller ☁☁☁ Fedora Cloud Architect ☁☁☁ mattdm@fedoraproject.org -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
On Wed, 2 Oct 2013 21:38:26 -0400 Matthew Miller mattdm@fedoraproject.org wrote:
On Wed, Oct 02, 2013 at 07:55:51PM -0500, Ranjan Maitra wrote:
0 * * * * maitra DISPLAY=:0.0 $HOME/scripts/yum/check-kernel.sh
Did you try the things in the blog post I'd linked to? As I said in my previous method, notify-send needs to talk to your dbus session, and it can't get that from inside cron.
http://earlruby.org/2008/08/update-pidgin-status-using-cron/
has a way of working around that.
Following, this post pointed to me my Matthew Miller, I am able to get things working. Here is what I did (same as in the post there).
Created a file as follows (called ~/bin/export_x_info):
#!/bin/bash # Export the dbus session address on startup so it can be used by cron touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
---- make the file executable:
$ chmod 700 ~/bin/export_x_info
Change this to be sourced at startup. I added the line to ~/.config/openbox/autostart:
/home/maitra/bin/export_x_info&
----
added the following line to crontab (via crontab -e):
37 * * * * source $HOME/.Xdbus; nice -n 19 $HOME/scripts/yum/check-kernel.sh
This works now!
Thanks very much everybody's help! Best wishes, Ranjan
____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium
On 10/03/2013 02:38 PM, Ranjan Maitra wrote:
#!/bin/bash # Export the dbus session address on startup so it can be used by cron touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
The first executable line is redundant, because when you redirect the output of the env to ~/.Xdbus, that will create it, meaning that the chmod line can be moved down one, so that the file exists when the command is executed. I'm not saying that you have to do it this way, but it just looks cleaner the other way, at least to me. YMMV, and it's your system.
On Thu, 3 Oct 2013 15:00:55 -0700 Joe Zeff joe@zeff.us wrote:
On 10/03/2013 02:38 PM, Ranjan Maitra wrote:
#!/bin/bash # Export the dbus session address on startup so it can be used by cron touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
The first executable line is redundant, because when you redirect the output of the env to ~/.Xdbus, that will create it, meaning that the chmod line can be moved down one, so that the file exists when the command is executed. I'm not saying that you have to do it this way, but it just looks cleaner the other way, at least to me. YMMV, and it's your system.
I think I agree with you. So, basically, then have the following in ~/bin/export_x_info:
#!/bin/bash # Export the dbus session address on startup so it can be used by cron env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus chmod 600 $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
Thanks, Ranjan
On Thu, Oct 03, 2013 at 03:00:55PM -0700, Joe Zeff wrote:
touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
The first executable line is redundant, because when you redirect the output of the env to ~/.Xdbus, that will create it, meaning that the chmod line can be moved down one, so that the file exists when the command is executed. I'm not saying that you have to do it this way, but it just looks cleaner the other way, at least to me. YMMV, and it's your system.
It's not a big deal, but if you do it that way, there will be a brief instant when the permissions may be more open than 600, during which someone else could maybe steal the contents. On Fedora, the default will be 664, which is world-readable. Your home directory may also be readable by others, so they could theeeeretically try to steal your DBUS_SESSION_BUS_ADDRESS.
On 03.10.2013 23:38, Ranjan Maitra wrote:
Following, this post pointed to me my Matthew Miller, I am able to get things working. Here is what I did (same as in the post there).
Created a file as follows (called ~/bin/export_x_info):
#!/bin/bash # Export the dbus session address on startup so it can be used by cron touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
make the file executable:
$ chmod 700 ~/bin/export_x_info
Change this to be sourced at startup. I added the line to ~/.config/openbox/autostart:
/home/maitra/bin/export_x_info&
added the following line to crontab (via crontab -e):
37 * * * * source $HOME/.Xdbus; nice -n 19 $HOME/scripts/yum/check-kernel.sh
This works now!
Thanks very much everybody's help! Best wishes, Ranjan
For this we use The Desktop Environments and The Display Managers. :) For the full GNU/Linux experience, I recommend something called LFS[1], Now, that's a real fun. ;) Remember, the second you go through those doors, everything changes. Our old life is done. Let's go for a little ride.
poma
On 10/02/2013 05:55 PM, Ranjan Maitra wrote:
Thanks! But this does not "work" either.
There may be a much easier way: before your cron job starts the update, have it do this:
yum check-update > /tmp/updates.txt
Then, after the update, grep /tmp/updates.txt looking for kernel, redirecting the output to /dev/null because all you need is the exit status. If there are any matches, it returns 0 and the script can notify you that it needs rebooting. (Sending email might be the best way.) If not, it does nothing. And, the nice thing about this is that it ends up being exactly one script, run once a day.
On 03.10.2013 02:55, Ranjan Maitra wrote:
Thanks! But this does not "work" either. Here is what I tried in my crontab -e:
0 * * * * maitra DISPLAY=:0.0 $HOME/scripts/yum/check-kernel.sh
(maitra is my username).
Here is how I changed my check-kernel.sh, though I am not sure if there was a problem with the earlier one....
$more check-kernel.sh
#!/bin/bash # from http://goo.gl/Mqq6UP
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: " \ "<b><i>Running</i></b> kernel is <b><i>$(uname -r | awk '{gsub(/*PAE/,""); print}')</i></b> but <b>latest</b> <b><u>installed</u></b> is <b><u>${latestkernel}</u></b> required <b><u>REBOOT</u></b>" fi;
How do you get yours to work?
(Works fine from the commandline, of course.) Btw, FWIW, I am using dunst.
http://goo.gl/Mqq6UP Cronie-notify-send-Dunst-Openbox.webm
poma
On 10/02/2013 08:10 AM, Ranjan Maitra wrote:
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed.
Why? If you only update the machine once a day, checking for a new kernel 24 times per day is redundant. Either add it to the script running yum, or have it run once a day, an hour after the update.
On Wed, Oct 2, 2013 at 10:10 AM, Ranjan Maitra maitra.mbox.ignored@inbox.com wrote:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
export DISPLAY=:0
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
Give that a try if you haven't yet Ranjan.
John
On Wed, 2 Oct 2013 20:53:52 -0500 inode0 inode0@gmail.com wrote:
On Wed, Oct 2, 2013 at 10:10 AM, Ranjan Maitra maitra.mbox.ignored@inbox.com wrote:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
export DISPLAY=:0
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
Got it! This works. However, I will also look at the link suggested by Matthew Miller (and also by Rick later on). I suspect that that is more general.
Many thanks again for all the help! This is what makes this mailing list the best!! The link suggested by Matthew Miller ( http://earlruby.org/2008/08/update-pidgin-status-using-cron/ ) and the points provided by all others provided a lot of explanation and shed light into things I did not know much about.
Ranjan
____________________________________________________________ GET FREE 5GB EMAIL - Check out spam free email with many cool features! Visit http://www.inbox.com/email to find out more!
On Wed, 2 Oct 2013 20:53:52 -0500 inode0 inode0@gmail.com wrote:
On Wed, Oct 2, 2013 at 10:10 AM, Ranjan Maitra maitra.mbox.ignored@inbox.com wrote:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
export DISPLAY=:0
I was wondering -- why, instead of this, the following would not work:
export $(env | grep DISPLAY)
Note that:
echo $(env | grep DISPLAY)>/tmp/tmp.txt
creates a blank file so there is a problem, clearly.
Just trying to see if I can easily hardcode the DISPLAY variable.
Thanks! Ranjan
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
Give that a try if you haven't yet Ranjan.
John
users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
On Wed, Oct 2, 2013 at 10:42 PM, Ranjan Maitra maitra.mbox.ignored@inbox.com wrote:
On Wed, 2 Oct 2013 20:53:52 -0500 inode0 inode0@gmail.com wrote:
On Wed, Oct 2, 2013 at 10:10 AM, Ranjan Maitra maitra.mbox.ignored@inbox.com wrote:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
export DISPLAY=:0
I was wondering -- why, instead of this, the following would not work:
export $(env | grep DISPLAY)
DISPLAY is not set in the environment used by cron. That was the whole problem to begin with.
John
Is the script executable?
-b
On 10/02/2013 05:10 PM, Ranjan Maitra wrote:
Hi,
I have a cron job running which yum updates all my machines once a day. All of these work fine.
I also have a cron job which checks for kernel updates every hour and sends me a message if an updated kernel has been installed. Here is the relevant script:
--- begin file called check-kernel.sh in my scripts/yum directory---
#!/bin/bash
latestkernel=$(rpm -q kernel |tail -n1|sed -e 's/kernel-//')
#echo "$latestkernel"
if uname -a | grep -qv "$latestkernel"; then notify-send "Kernel UPDATE on ${HOSTNAME}: Running Kernel is $(uname -r) but lat est installed rpm is ${latestkernel}; REBOOT required" fi;
--- end file called check-kernel.sh ---
(A bit wordy, I know.)
I have verified that this is executable and works from the commandline without any errors.
I have the following set up via crontab -e:
0,15,30,45 * * * * nice -n 19 $HOME/.xplanet/download_xplanet_cloudmap 5 * * * * nice -n 19 $HOME/scripts/yum/check-kernel.sh
The first line downloads cloudmaps for use with xplanet and works just fine (or appears to) and has done so for aeons.
However, nothing happens (or appears to) for the second line.
What is wrong here?
Many thanks and best wishes, Ranjan