Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have written a bash script that monitors the output of sensors and uses notify-send to alert me when my notebook is overheating. I start the script with watch -n 15 fullscriptname and also added this line to /etc/rc.local

It works as it should when I start it from the terminal and the process is also running after startup. However then the notifications don't show up. I assume it is because rc.local is executed by root.

(I also tried to add it to Startup Applications via Unity, but this also doesn't work).

So my questions: Is there a way to start a process as a user? What is the proper way for automatically starting such a script (which configuration files do I use)?

share|improve this question
    
You can use su to execute a command as a different user, but for your use case, terdon's answer is the way to go. –  n.st Sep 29 '13 at 13:47

1 Answer 1

up vote 0 down vote accepted

The easiest way would be have cron start it. Run crontab -e that should open your crontab in your default editor, add this line to it, save and close it:

@reboot watch -n 15 /path/to/script

Another option would be adding watch -n 15 /path/to/script to your ~/.Xsession file but I'm not sure if Ubuntu still loads that.

share|improve this answer
    
hm, I got the watch process now running with the correct user (after setting TERM=dumb cron is no longer sending an error mail). But somehow the notifications don't reach my desktop. Anyways, thanks for the hint with crontab –  ndldd Sep 29 '13 at 15:16
    
@ndldd capture any errors produced by the cron: @reboot watch -n 15 /path/to/script 2>/tmp/error. That way you can see what is wrong. –  terdon Sep 29 '13 at 15:20
    
I installed postfix for localmail and I got an Email from Cron: 'Error opening terminal: unknown.' but I think I fixed this now as I'm no longer getting error mails and the process runs. The problem is now with the script itself if I run it manually in the background by appending '&' the notifications are also not shown. edit: Just found a possible solution: commandlinefu.com/commands/view/6167/… –  ndldd Sep 29 '13 at 15:45
    
Yes, I got it finally working, thanks for the help, I added SHELL=/bin/bash DISPLAY=:0.0 XAUTHORITY=~/.Xauthority TERM=dumb above the crontab line. –  ndldd Sep 29 '13 at 15:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.