LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Can't run Python code at Boot - Ubuntu Karmic (http://www.linuxquestions.org/questions/linux-kernel-70/can%27t-run-python-code-at-boot-ubuntu-karmic-784701/)

micksulley 01-25-2010 04:33 PM

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

pattwo 01-29-2010 08:38 PM

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


All times are GMT -5. The time now is 09:11 PM.