Reputation: 17382
I want to write a script in Linux which will notify me every half an hour by some alert message or something, whenever I'm logged onto the system. how can I do something like that on OS level?? It's a mixture of cronjob and javascipt alert message. how can I do it?
Upvotes: 0
Views: 1228
Reputation: 60068
Put the following in your user-level crontab. You can open it by typing crontab -e
in your terminal.
30 * * * * DISPLAY=:0.0 notify-send "Red alert" "All personnel must evacuate"
notify-send
will display a GUI notification. It needs the DISPLAY
env variable to be correctly set to the display you're logged on (most likely :0.0). (For some GUI apps, you might need additional env variables such as DBUS_SESSION_BUS_ADDRESS
).
For testing purposes, replace 30
with *
to get that message every minute, rather than each 30th minute.
More on: https://help.ubuntu.com/community/CronHowto
Upvotes: 0
Reputation: 17382
I found a solution :-
import sys
import pynotify
if __name__ == "__main__":
if not pynotify.init("icon-summary-body"):
sys.exit(1)
n = pynotify.Notification("Heading","content","notification-message-im")
n.show()
and then run a cronjob
Upvotes: 1
Reputation: 4959
I think what you're looking for is a mixture of cron and write. Keep in mind that though it does allow you to send messages to terminals, receiving a message can mess things up in fullscreen programs (e.g vim or emacs).
EDIT: if you want a window to pop up, I recommend xmessage or zenity
Source: http://ubuntuforums.org/showthread.php?t=876618
Upvotes: 0
Reputation: 2085
A simple way for having a script writing you a message every half hour on your shell would be, in C :
void main()
{
while (1) {
sleep(1800);
printf("My Message \n"); }
}
Compiling this using gcc
gcc myfile -o my_script && chmod +x my_script
Open your main terminal & write :
./my_script &
You'll keep working on your shell, and every half hour, your message will pop up; you can use stringformats to include beeps in the printf for example, or just go do whatever you'd like instead.
Edit: For printing a pop-up in your system, you'll need to use kdialog -like tools, i'll be printing an example with kdialog, since that is working on my system, but things like gtk-dialog-info or else might work aswell :
#!/bin/sh
while :
do
kdialog --msgbox "MyMessage";
sleep 1800;
done
And doing in the shell :
sh myscript.sh &
Upvotes: 0
Reputation: 4237
Do you need the notification in a window environment or just a notification in some way? The easiest would probably be to use cronjobs MAILTO tag to define a recipient to the output of the executed script.
Like so:
[email protected]
* * * * bash ~/test.sh
Alternatively, you could just make the computer beep in different patterns at different times using cron. On Ubuntu at least, there's a utility called beep that should make this very easy.
Upvotes: 0