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

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.
Soumen RoySenior ManagerAsked:
Who is Participating?
 
omarfaridCommented:
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
 
omarfaridCommented:
For crontab jobs:

- set required env. variables e.g. PATH
- use full pathnames for files and folders
- redirect stdin, stdout & stderr
0
 
Soumen RoySenior ManagerAuthor Commented:
@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
 
omarfaridCommented:
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
 
Soumen RoySenior ManagerAuthor Commented:
Thank you, I will try it and tell if it has been solved..
0
 
Soumen RoySenior ManagerAuthor Commented:
May I ask you what do you mean by "source your ~/.bash_profile ", please?

Regards,
Soumen
0
 
Soumen RoySenior ManagerAuthor Commented:
That worked.

Thank you.

Sorry for such a late reply.
0
 
omarfaridCommented:
No problem :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.