LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 01-25-2010, 04:33 PM   #1
micksulley
LQ Newbie
 
Registered: Jan 2010
Location: UK
Distribution: Ubuntu 64 bit
Posts: 8

Rep: Reputation: 0
Can't run Python code at Boot - Ubuntu Karmic


Hi,

I want to run a python code at boot, but it is not working. I have created a file cron_test in /etc/cron.d/

Code:
# /etc/cron.d/cron_test
# tests how to run a python script at startup
@reboot touch /home/mick/ct.log
@reboot ./home/mick/cron_test.sh
cron_test_sh is
Code:
cd /home/mick
touch ct_sh.log
./cron_test.py
and cron_test.py is
Code:
#!/usr/bin/python
    
strt_log_file = open('/home/mick/test.log',  'a') 

pr_str = "\n\n\t\t#########################################\n"
pr_str = pr_str + "\t\t### Test of cron jobs. ###\n"
pr_str = pr_str + "\t\t#########################################\n"

pr_str = pr_str + "\n\nEnd of cron test file ..."

strt_log_file.write(pr_str)
if I run cron_test.sh in a terminal is works fine, but when I reboot it does nothing, even the touch in cron_test within cron.d does not happen.

What have I missed?

I am running Ubuntu Karmic (9.10)

Thanks
Mick
 
Old 01-29-2010, 08:38 PM   #2
pattwo
LQ Newbie
 
Registered: Jun 2008
Location: Ontario, Canada
Distribution: Slackware
Posts: 7

Rep: Reputation: 5
Hi

In your /etc/cron.d/cron_test you didn't specify which user the commands are supposed to run as.

It should work if you add a username between the @reboot tag and the command, like this

Code:
@reboot someuser /usr/bin/python /home/someuser/cron_test.py
where someuser is a valid user on your system.

Pat

Last edited by pattwo; 01-29-2010 at 08:40 PM.
 
  


Reply

Tags
cron, python, reboot


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Ubuntu How to run Python script on Login? warnetgm Linux - General 14 03-13-2012 06:11 PM
LXer: How to Run Enlightenment (E17) On Ubuntu Karmic LXer Syndicated Linux News 0 01-16-2010 07:40 AM
Slow Boot in Linux in Ubuntu Karmic route277 Linux - Newbie 8 12-19-2009 02:39 AM
LXer: Ubuntu Karmic fail: Pidgin and the new Empathy won't run in some cases until yo LXer Syndicated Linux News 0 11-04-2009 09:30 PM
How do I make python programs run without entering the command python? trist007 Programming 5 03-22-2009 08:21 PM


All times are GMT -5. The time now is 03:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration