0

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?

asked Oct 12, 2014 at 19:03
2
  • You've already indicated that you know about cron. Go forth and program! Commented Oct 12, 2014 at 19:07
  • I can run a cron job, but how will I to throw an alert message? Any idea? Commented Oct 12, 2014 at 19:14

5 Answers 5

1

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

answered Oct 12, 2014 at 20:07
Sign up to request clarification or add additional context in comments.

Comments

0

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.

answered Oct 12, 2014 at 19:15

1 Comment

I dont want my mail-box to get filled with the messages. I rather want it in a window environment (just like a popup). Any idea ?? how will I do it?
0

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 &
answered Oct 12, 2014 at 19:07

7 Comments

Thanks Mekap for for a quick response, but I dont want my message to printed on the terminal, but rather like a alert(pop-up). Any idea regarding that?
Yes, i'm editing my message right now. Please tell me what linux are you on.
Alright ! Use Zenity instead of kdialog then ! Zenity is an ubuntu package you'll find easily.
This solution has several flaws: it re-invents the wheel, it doesn't work outside of the terminal its run in, and it's not terribly portable. Better to use built-in tools in Linux like cron.
@whereswalden Was willing to give a cron-free solution, since it sounded to me that he doens't wanted to use cron.
|
0

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

answered Oct 12, 2014 at 19:32

1 Comment

I tried, and they worked, but is there something like a notification message (that appears in the top right corner of the screen) but not a dialog box?
0

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

answered Oct 12, 2014 at 20:53

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.