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?
-
You've already indicated that you know about cron. Go forth and program!Jonathon Reinhart– Jonathon Reinhart2014年10月12日 19:07:19 +00:00Commented Oct 12, 2014 at 19:07
-
I can run a cron job, but how will I to throw an alert message? Any idea?Praful Bagai– Praful Bagai2014年10月12日 19:14:05 +00:00Commented Oct 12, 2014 at 19:14
5 Answers 5
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
Comments
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.
1 Comment
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 &
7 Comments
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
1 Comment
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.