Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Forum Archive > Main Support Categories > General Help
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.
Ubuntu 9.10 is out!!!

When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu.

The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely.

General Help
All your general support questions for Ubuntu, Kubuntu, Edubuntu and Xubuntu.

 
Thread Tools Display Modes
Old October 5th, 2007   #1
puffyzacd
5 Cups of Ubuntu
 
Join Date: Oct 2006
My beans are hidden!
Trouble scheduling task

Hey guys,

I'm kinda a newbie to linux, but I'm trying to figure everything out. I've been working for a while on this one thing and I'm not having much luck, maybe someone here can help!

I want to schedule the computer to be locked down every 2 days...So I tried to use anacron to run gnome-screensaver-command -l, no dice. I think this is because anacron runs everything as root, and the command needs to be run by me (it works from the terminal when I run "gnome-screensaver-command -l"). I tried using sudo -u to run it as my username, but this doesn't even work from the terminal. It says "Sorry, user zac is not allowed to execute '/usr/bin/gnome-screensaver-command' as zac on ubuntu."

Anyway, does anyone have some advice about this? Or an alternative method?

Thanks!

-Zac
puffyzacd is offline   Reply With Quote
Old October 6th, 2007   #2
dcstar
Ubuntu addict and loving it
 
Join Date: Feb 2005
Location: Melbourne, Australia
Beans: 7,067
Ubuntu 9.04 Jaunty Jackalope
Re: Trouble scheduling task

Quote:
Originally Posted by puffyzacd View Post
Hey guys,

I'm kinda a newbie to linux, but I'm trying to figure everything out. I've been working for a while on this one thing and I'm not having much luck, maybe someone here can help!

I want to schedule the computer to be locked down every 2 days...So I tried to use anacron to run gnome-screensaver-command -l, no dice. I think this is because anacron runs everything as root, and the command needs to be run by me (it works from the terminal when I run "gnome-screensaver-command -l"). I tried using sudo -u to run it as my username, but this doesn't even work from the terminal. It says "Sorry, user zac is not allowed to execute '/usr/bin/gnome-screensaver-command' as zac on ubuntu."

Anyway, does anyone have some advice about this? Or an alternative method?

Thanks!

-Zac
You cannot run X commands from cron unless you have the actual X session screen to be used specified in the environment.

Do a search for running graphical X apps from cron, there should be numerous posts to solve the problem.
__________________
Regards, David.

The Forum search function is useful for immediate help (give it a try).
Please mark your thread as "Solved" (using the Thread Tools) when appropriate.
dcstar is offline   Reply With Quote
Old October 6th, 2007   #3
Herman
Ubuntu addict and loving it
 
Herman's Avatar
 
Join Date: Jul 2005
Location: Hughenden, Australia
Beans: 4,089
Ubuntu 9.04 Jaunty Jackalope
Re: Trouble scheduling task

Yes puffyzacd, dcstar is right, you need the export variable, check this link out, crontab: How to run GUI programs with cron

It works for me, my computer wakes me up every morning with Totem Movie Player playing a music file for me, I set it up with crontab.
I used to need to boot into KDE before that, for Kalarm.

Regards, Herman
Herman is online now   Reply With Quote
Old October 6th, 2007   #4
puffyzacd
5 Cups of Ubuntu
 
Join Date: Oct 2006
My beans are hidden!
Re: Trouble scheduling task

Thanks for the help both of you, I think this solved one of the problems I'm having.

However, I'm still having trouble running this job. I made a test crontab file which looks like this:

Code:
* * * * * export DISPLAY=:0 && /usr/bin/gnome-screensaver-command -l
As was suggested, I added the export DISPLAY=:0 part in order to run the GUI app from cron. The above runs every minute (according to the /var/log/syslog file), but my screen does not lock up. I wish I could provide more information, is there a way to debug the output from the commands cron runs?

Thanks again for your help!

-Zac
puffyzacd is offline   Reply With Quote
Old October 6th, 2007   #5
Herman
Ubuntu addict and loving it
 
Herman's Avatar
 
Join Date: Jul 2005
Location: Hughenden, Australia
Beans: 4,089
Ubuntu 9.04 Jaunty Jackalope
Re: Trouble scheduling task

Well I have been trying for hours now and you're right, it runs fine from a regular terminal, but I can't seem to get it to run from crontab either.
I have other tasks running from crontab, so we should be able to get this one running to (eventually).

I tried editing /etc/crontab and running it from my username and as root, neither worked.

I tried making a script with the command: gnome-screensaver-command -l
in it too, and running that from crontab to I can run the command indirectly. That didn't work either.
The script itself works okay whenever I run it the normal way.

I did also try something blindingly simple that works fine!
I went 'System'-->'Administration'-->'Screensaver', and opened the Screensaver Preferences window.
There I marked the box for 'Activate the screensaver when the computer is idle', with an X.
I also marked 'Lock screen when screensaver is active'
That was a simple way to get the screen to lock, but it's only possible to set the timer for it for between one minute and two hours, not two days.
However, it does seem to at least partially satisfy your requirements.

SO far I have been unable to come up with anything better.
Regards, Herman
Herman is online now   Reply With Quote
Old October 6th, 2007   #6
puffyzacd
5 Cups of Ubuntu
 
Join Date: Oct 2006
My beans are hidden!
Re: Trouble scheduling task

Thank you Herman for all your hard work! I only wish we had more to show for it.

My subsequent efforts have proved fruitless as well, so I think I'm about ready to give up on gnome-screensaver-command and start looking for an alternative way to get something like this up-and-running.

I'll come back and leave a post if I figure something out.

-Zac
puffyzacd is offline   Reply With Quote
Old October 6th, 2007   #7
Herman
Ubuntu addict and loving it
 
Herman's Avatar
 
Join Date: Jul 2005
Location: Hughenden, Australia
Beans: 4,089
Ubuntu 9.04 Jaunty Jackalope
Re: Trouble scheduling task

Yes, me too ' I'm still trying, I'm reading the man page for the 'at' command right now, The 'at' command looks a bit promising so far....
Maybe the 'at' command is what we're looking for.
Herman is online now   Reply With Quote
Old October 6th, 2007   #8
Herman
Ubuntu addict and loving it
 
Herman's Avatar
 
Join Date: Jul 2005
Location: Hughenden, Australia
Beans: 4,089
Ubuntu 9.04 Jaunty Jackalope
Re: Trouble scheduling task

YAY!
I think I have made a step in the right direction, I used the 'at' command to schedule my shell script to run our '/usr/bin/gnome-screensaver-command -l' command and it seems to be working well for me!

Here is an example of my shell script (probably most of us already know, but just for the benefit of those who might not be sure),
1. Open a blank gedit text editor page and name it 'lockscreen.sh'.
Code:
sudo gedit lockscreen.sh
Type in or copy and paste the following text,
Code:
#!/bin/bash
/usr/bin/gnome-screensaver-command -l
Save and close the file.
Make it executable, (by giving it the right file permissions)
Code:
sudo chmod 0755 lockscreen.sh
Okay, now for the 'at' command that will run the lockscreen.sh script,
Code:
at 14:00 < lockscreen.sh
NOTE: you can substitute and time you like for '14:00'
I have tested that a few times already, now all we need to do is get is practice with it some more and learn how to set it to any times and dates we like.
To see what time formats the 'at' comamnd will accept we need to read the file: /usr/share/doc/at/timespec,
Code:
cat /usr/share/doc/at/timespec
I think we're on the home stretch now!

Regards, Herman
Herman is online now   Reply With Quote
Old October 6th, 2007   #9
HermanAB
make bzImage, not war
 
Join Date: Oct 2005
Location: Calgary
Beans: 4,587
Ubuntu Jaunty Jackalope (testing)
Send a message via Skype™ to HermanAB
Re: Trouble scheduling task

The cron system has a very limited environment. When you call a program from a cron script, then you always have to supply the full path.

The at system is different, it runs with the environment of the user that called it.

Cheers,

Herman
__________________
Cheers,

Herman
http://aeronetworks.ca/linuxhowtos.html
HermanAB is offline   Reply With Quote
Old October 7th, 2007   #10
Herman
Ubuntu addict and loving it
 
Herman's Avatar
 
Join Date: Jul 2005
Location: Hughenden, Australia
Beans: 4,089
Ubuntu 9.04 Jaunty Jackalope
Re: Trouble scheduling task

Hey, thanks Herman!

Do you know how to program this to run every two days? I am still trying to work out how to do that part of it now.
So far I have made another script and I named it: at_command.sh, it contains (as you might guess), an 'at' command that is supposed to in turn run the lockscreen script.

Now, what I am testing is this, the at_command.sh script has two commands in it, one to activate the other script right away, and another command to re-activate its-self (recursively), at a given time interval.
For example,
Code:
#!/bin/bash

at now < lockscreen.sh
at now + 5 minutes < at_command.sh
He-he, if it will work every five minutres I'm optimistic we can just change that to 'now + 2 days' and we'll be all set!

Do you think it will work?

Regards, Herman
Herman is online now   Reply With Quote

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:58 PM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry