Running python script before user login
nt_mahmood at yahoo.com
Sun Aug 22 15:13:27 CEST 2010
I am trying to execute this script before login:
date > /home/mahmood/dateatboot.txt
echo "In local file"
echo "python script finished"
after restart, dateatboot.txt was created shows that the script was executed.
In the python file, I have this:
import smtplib, commands, os, datetime
# find IP address and write to file
print 'I am in python file'
f = open('.ip.txt', 'w')
After boot there is no .ip.txt file.
// Naderan *Mahmood;
From: Thomas Jollans <thomas at jollybox.de>
To: python-list at python.org
Sent: Sun, August 22, 2010 3:17:57 PM
Subject: Re: Running python script before user login
On Sunday 22 August 2010, it occurred to Mahmood Naderan to exclaim:
> >Specify exactly how it's not working.
> I have wrote a script to send my ip address to an email address. It does
> work when I am login (python sendip.py). I then followed the procedure in
> https://help.ubuntu.com/community/RcLocalHowto. However after restart, no
> email is sent.
The first step would be to make sure your init script is actually running. Add
some simple command that you know will not fail, and where you can see easily
that it worked. Say, you could use
date > /home/[USER]/Desktop/created_during_boot.txt
as an init script. Then you could see that, if the file was created on your
desktop, that the script is running at all. When you know that, THEN you can
start to worry about Python
(I think Ubuntu probably doesn't bring up the network before NetworkManager
does this after login. So you might just not be able to send e-mail before
login. You can check this by saving the output of /sbin/ifconfig somewhere)
> // Naderan *Mahmood;
> From: Chris Rebert <clp2 at rebertia.com>
> To: Mahmood Naderan <nt_mahmood at yahoo.com>
> Cc: python mailing list <python-list at python.org>
> Sent: Sun, August 22, 2010 1:28:45 PM
> Subject: Re: Running python script before user login
> On Sun, Aug 22, 2010 at 1:52 AM, Mahmood Naderan <nt_mahmood at yahoo.com>
> > I have wrote a python script and want to run it before user login. To do
> > that, I have added it to the ubuntu startup file (init.d). However it
> > seems that the script doesn't work.
> Specify exactly how it's not working.
> More details = Better assistance
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list