Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Running python script before user login

Reply
Thread Tools

Re: Running python script before user login

 
 
Thomas Jollans
Guest
Posts: n/a
 
      08-22-2010
On Sunday 22 August 2010, it occurred to Mahmood Naderan to exclaim:
> I am trying to execute this script before login:
>
> #!/bin/sh
> date > /home/mahmood/dateatboot.txt
> echo "In local file"
> /usr/bin/python2.6 /home/mahmood/sendip.py
> 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')
> f.write( commands.getoutput("ifconfig").split("\n")[1].split()[1][5:])
> f.close()
> ...
>
> After boot there is no .ip.txt file.


Where are you looking? Do you actually know in which working directory your
script is being executed?

How about something like this:

#!/bin/sh

cd /home/mahmood/

python sendip.py >sendip.log 2>&1


.... this will write Python's output to a log file. If there is an exception,
you'd be able to see it.

>
>
> // Naderan *Mahmood;
>
>
>
>
> ________________________________
> From: Thomas Jollans <>
> To: python-
> 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
>
> #!/bin/sh
>
> 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 <>
> > To: Mahmood Naderan <>
> > Cc: python mailing list <python->
> > 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 <>

>
> wrote:
> > > 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.
> >
> > Cheers,
> > Chris
> > --
> > More details = Better assistance

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can code in a script file start running before file loaded? Joe Nine Javascript 3 03-28-2010 06:54 PM
Cannot open user default database. Login failed. Login failed for user 'HEMPC\ASPNET' Tony Johansson ASP .Net 3 01-02-2010 04:09 PM
modify a long-running python script while it is running? Benjamin Rutt Python 2 12-20-2005 01:42 PM
check interpreter version before running script rbt Python 8 04-06-2005 01:21 PM
Running client script before a postback initated by an asp button Marshal Antony ASP .Net 3 01-21-2004 11:44 PM



Advertisments