Author Topic: zenity again  (Read 3049 times)

Online critter

  • Full Member
  • ***
  • Posts: 220
zenity again
« on: September 04, 2009, 03:22:34 PM »
As the previous thread on zenity has gone stale I thought I would start a new topic.

I have a local copy of the repositories on my file server which I use to save over-using my metered broadband whilst keeping all of my networked and other remote systems up-to date.

I use rsync in a bash script to keep the repository updated and this script is executed daily (nightly) by cron

If I run the script directly in a terminal I get a zenity dialog giving me a summary of the rsync log file. When the script is executed by cron I don't get the summary dialog even though the script has been executed by cron and the logfile has been updated. >:(

kdialog doesn't report through cron either.. :(

This could be a cron/root permissions thing but I can't find out why.

Any ideas anybody? ???
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

musonio

  • Guest
Re: zenity again
« Reply #1 on: September 04, 2009, 05:25:55 PM »
I have absolutely no answer to your question.
I'm just curious about the script. If you have time, could you post it here?

Online critter

  • Full Member
  • ***
  • Posts: 220
Re: zenity again
« Reply #2 on: September 05, 2009, 01:05:54 AM »
My pleasure Musonio - do with it what you will  :)

Code: [Select]
#!/bin/bash
#syncronise my local repository with a remote one
#
#clean up the temporary files from the previous run if they exist
if [ -f /tmp/sync-log ]
then
rm -f /tmp/sync-log
fi

if [ -f /tmp/sync-tmp ]
then
rm -f /tmp/sync-tmp
fi

#synchronise the repositories
rsync -aPv --no-motd --stats --delete  --log-file=/var/update.log --exclude=SRPM* ftp.heanet.ie::pub/pclinuxos/apt/pclinuxos/2007/ /data/repo/2009/

#set up the report header
echo "report from: " > /tmp/sync-tmp
cut -d" " -f1 <<< `tail -n 1 /var/update.log | grep speedup` | cut -d"/" -f3 >> /tmp/sync-tmp
echo " - " >> /tmp/sync-tmp
cut -d" " -f1 <<< `tail -n 1 /var/update.log | grep speedup` | cut -d"/" -f2 >> /tmp/sync-tmp
echo " - " >> /tmp/sync-tmp
#remove extra newlines - actually, translate them into spaces
tr "\n" " " < /tmp/sync-tmp > /tmp/sync-log
cut -d" " -f1 <<< `tail -n 1 /var/update.log | grep speedup` | cut -d"/" -f1 >> /tmp/sync-log
#add a blank line before the report body
echo "" >> /tmp/sync-log

#report body
#cut out only the parts we're interested in and add them to the report
cut -d" " -f4-8 <<< `tail -n 15 /var/update.log | grep size:` >> /tmp/sync-log
cut -d" " -f4-8 <<< `tail -n 15 /var/update.log | grep files:` >> /tmp/sync-log
cut -d" " -f4-8 <<< `tail -n 15 /var/update.log | grep transferred:` >> /tmp/sync-log
cut -d" " -f4-8 <<< `tail -n 15 /var/update.log | grep received:` >> /tmp/sync-log

#bring up the dialog as a background task
zenity --title=repo-sync-report --text-info --width 500 --height 400 --filename=/tmp/sync-log &
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

musonio

  • Guest
Re: zenity again
« Reply #3 on: September 05, 2009, 04:39:52 AM »
Thanks. I hope someone can help you.

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: zenity again
« Reply #4 on: September 05, 2009, 05:32:21 AM »
Sorry I cannot help with cron, but I do want to thank you for posting your script ........ I can now use that in place of Grsync which has failed on me, with a few modifications for my circumstances.

It came just at the right time .... doing this was on my list for today   ;D

My only comment in relation to my own situation is that I will not have the log file saving to /var/log as I will be running the script as user not root.

Very timely .... thanks again and sorry I cannot help with cron. (would it be that it is running as root and the Zenity report is only available to root?)

regards.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: zenity again
« Reply #5 on: September 05, 2009, 08:03:37 AM »
Perhaps you could add a line to have the log copied to your /home.


Online critter

  • Full Member
  • ***
  • Posts: 220
Re: zenity again
« Reply #6 on: September 05, 2009, 10:54:03 AM »
Perhaps you could add a line to have the log copied to your /home.



@ Neal
My original script saves the log file to my home directory, I changed the script for 'publication' ;)
just caught your interview in the mag, nice read. Paul is doing a great job with mag DYT? :)

Nice to know johnboy, good luck with it. BTW,
I run the script as root (su). It seems to make cron happier.

It all works OK as is but I would have liked the cron part to have worked as I have another script  (work in progress) that harvests the download size and totals it per month so that I can keep an eye on my 'metered' connection and warns me if I get near to getting a surcharge.
I'd like to know if anybody gets any mileage from this. :)
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: zenity again
« Reply #7 on: September 05, 2009, 01:15:19 PM »
Quote
I run the script as root (su). It seems to make cron happier.

My point above was that if the script is run as root, then zenity is run as root and its output might only be visible by root. If that is the case then as user you will not see it.  ;)

Online critter

  • Full Member
  • ***
  • Posts: 220
Re: zenity again
« Reply #8 on: September 05, 2009, 02:16:05 PM »
Quote
My point above was that if the script is run as root, then zenity is run as root and its output might only be visible by root. If that is the case then as user you will not see it.

Hmmm! good point johnboy If I ever sober up then I might look into that. :D

don't worry, I onlly drink root (su) beer ;)
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

Offline collins601

  • Jr. Member
  • **
  • Posts: 29
Re: zenity again
« Reply #9 on: December 03, 2010, 05:39:09 PM »
I use rsync in a bash script to keep the repository updated and this script is executed daily (nightly) by cron

If I run the script directly in a terminal I get a zenity dialog giving me a summary of the rsync log file. When the script is executed by cron I don't get the summary dialog even though the script has been executed by cron and the logfile has been updated. >:(

kdialog doesn't report through cron either.. :(


I don't know the answer for your situation, but it's a hard and fast rule that all requests in cron to run a program must use the full path to the executable, ie /usr/bin/xxx rather than xxx. cron has a very minimal environment and does not share the normal $PATH in root or user.

HTH.

--
Collins

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
Re: zenity again
« Reply #10 on: December 20, 2010, 11:04:43 PM »
i also dont know the answer... but i recall seeing this awhile back:


I understand that cron is not a shell and can't run script and bash commands that it can't interpret. So for my issue I added what I called a "trigger" script which has a set of commands and instructions that cron can understand and then the last line of this "trigger" script will trigger the actual script which is located in /usr/bin/.   This "trigger" script is what compiled to solve this issue a year ago...but I honestly forgot that I posted this post in PCLOS forum and that's why it never has any further post....

... this trigger script:
http://pastebin.com/QhjhYtvC

I'm using Zenity as my popup/tray icon.  Because of this I was told that I had to tell cron what display to use and some other stuff that I don't totally understand yet.  That's why the trigger script is necessary.  

« Last Edit: December 20, 2010, 11:06:55 PM by travisn000 »

Offline Village Idiot

  • Hero Member
  • *****
  • Posts: 2345
  • Have A Nice Day.
Re: zenity again
« Reply #11 on: December 21, 2010, 12:29:53 AM »
I saw this thread awhile ago and today's post made me wonder why are you running the script as root? I have a machine here which, amongst other things, runs continuously sucking data off the internet including a daily repo rsync as an ordinary user joe-sixpack cronjob.

Why man, why?

Why do you say the script runs better as root? Then you have problems with the files/ownership/permissions. Why?    ??? ??? ???
$ fortune
No Microsoft products were used in any way for the creation of this message.
If you are using a Microsoft product to view it, BEWARE! - I'm not
responsible for any harm you might encounter as a result.

Online critter

  • Full Member
  • ***
  • Posts: 220
Re: zenity again
« Reply #12 on: December 21, 2010, 02:48:22 PM »
I saw this thread awhile ago and today's post made me wonder why are you running the script as root? I have a machine here which, amongst other things, runs continuously sucking data off the internet including a daily repo rsync as an ordinary user joe-sixpack cronjob.

Why man, why?

Why do you say the script runs better as root? Then you have problems with the files/ownership/permissions. Why?    ??? ??? ???

Because all of the files in my personal repository have only root r/w permissions and the scripts that access them are also restricted. This way only an administrator can cause a catastrophe. I am the only administrator and I know just how much damage I am capable of. Root admin. makes me think twice - Damage limitation ;)

Accidentally overwriting a 12 - 15 GB repository is a seriously 'bad hair day'. Believe me on this, I know! ::)

BTW. Thanks for the reply. :)
« Last Edit: December 21, 2010, 02:53:07 PM by critter »
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15829
  • LXDE! Coffee, Bacon and Cheesecake!
Re: zenity again
« Reply #13 on: December 21, 2010, 02:57:43 PM »
Had a thought. (Yea. It hurt. ;)) After the file is saved to your /home, you could, I think, change its permissions to be readable by you. Just add the lines to your script or write a separate script for the purpose and have it called after saving the file. Just a thought.


Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: zenity again
« Reply #14 on: December 21, 2010, 03:23:03 PM »
critter, have you tried calling the script with cron, and in place of having the Zenity line in the same script, put it in another and call that from the last line of the Cron script?

.....  seems foolish now that I have written it down ......   :-\