Solved

How do I send an email from raspberry pi at user login?

Posted on 2016-10-02
8
44 Views
Last Modified: 2016-10-22
Hello experts,

I want my raspberry pi to send me an email notification (on gmail) whenever an user logs in or logs out..

I tried running my script @reboot from crontab -e. The script runs well when tested, but cannot run at reboot or startup..

How do I get it working??

Thanks in advance.
0
Comment
Question by:Soumen Roy
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
For crontab jobs:

- set required env. variables e.g. PATH
- use full pathnames for files and folders
- redirect stdin, stdout & stderr
0
 

Author Comment

by:Soumen Roy
Comment Utility
@omararfarid

I am new to Linux, so it was a bit tough for me to understand..

I have set full pathnames though.. Here is a snap of the script and the cronjob list.
d.jpg
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 500 total points
Comment Utility
As I can see from the snapshot, you are using command like sudo, etc.

You need to either use full path names for commands or set env. variable PATH. It will be nice if you can source your ~/.bash_profile in the script. You can simply create a shell script and make it executable. In that script source your ~/.bash_profile then run other commands within that script.

In crontab call the script file.
0
 

Author Comment

by:Soumen Roy
Comment Utility
Thank you, I will try it and tell if it has been solved..
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Soumen Roy
Comment Utility
May I ask you what do you mean by "source your ~/.bash_profile ", please?

Regards,
Soumen
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
Comment Utility
bash has internal command called source. This command will read and set env. variables and execute commands in .bash_profile file located at home dir. If it doesn't work with ~/.bash_profile then use full pathname to your home dir. e.g.

source /path/to/myhomedir/.bash_profile

Please put the correct path name of your's
0
 

Author Comment

by:Soumen Roy
Comment Utility
That worked.

Thank you.

Sorry for such a late reply.
0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
No problem :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now