output
stringlengths 9
26.3k
| input
stringlengths 26
29.8k
| instruction
stringlengths 14
159
|
---|---|---|
I am now using Trysterobiff. It is a non-polling IMAP mail notifier for the
systray. It implements the requirements, including the execution of external
commands and does not crash.
I've written it using Qt, thus Trysterobiff is quite portable. The non-polling
operation is implemented using the IDLE extension of IMAP, i.e. you are immedialtely notified of new mail (in contrast to a polling approach).
|
I am searching for a small new-email-notifier for IMAP mailboxes that displays it's status in the icon-bar (how do you call it?) of a window manager.
Basically some biff/xbiff like tool ported to 21th century technology. ;)
I am using awesomewm, which is able to display in its taskbar the 'applets' (?), which also work under gnome (I guess that it implements some freedesktop standard).
Basic requirements:should not waste memory/CPU (e.g. a pythonGTK based solution probably would)
support for IMAPS, and should check the host TLS certificate
configurable poll intervalls
should not distract too much
nice interfaceNice to have:optional configuration of a user defined action (executing an external command) | IMAP mail notifier for window manager/task bar? |
The d-bus debug utility d-feet which is available as a package in many systems seems to be able to find the process id and command providing a service. For example, I ran it on a Fedora 23 xfce4 X11 systemd platform and selected Session Bus and entered the service name org.freedesktop.Notifications. It introspected the service, activating it, and showed the pid and /usr/lib64/xfce4/notifyd/xfce4-notifyd command: |
I can't find a way to find what program implements the org.freedesktop.Notifications service. Is it possible to ask DBus to tell me what program provides it?
The reason for asking this question is quite banal: I found a new desktop notifications daemon I'd like to use, but it won't start and instead complains with this message Name Lost. Is Another notification daemon running?However, I am unable to determine what program is holding the name. I already uninstalled every other notification daemon, restarted X server, and even rebooted the machine.
However, when I run this command:
dbus-send --session --dest=org.freedesktop.DBus --type=method_call \
--print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNamesstring "org.freedesktop.Notifications" is present in the output, so something is holding the name, and I can't start my desired daemon.
| Find out the owner of a DBus service name |
system crons
Did you look through these files & directories to make sure there isn't a duplicate cronjob present?/etc/crontab
/etc/cron.hourly/
/etc/cron.d/
/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/Also any files present in these directories that's executable will be run. Doesn't matter if it's a .placeholder name or whatever. You can use chmod 644 ... to disable any script that is executable.
user crontabs
Also check the following directory to see if there are any user's that have created their own crontabs:
For example:
$ sudo ls -l /var/spool/cron/
total 0
-rw------- 1 saml root 0 Jun 6 06:43 saml |
On a server I inherited, there is a cron job running hourly on one of the Debian servers. It sends an email out to a non-existent email, but bounces back to my account since I listed myself as the root email in /etc/aliases. The cron job has been deleted from /etc/cron.hourly (it was ntupdate), as it's listed in the email. I reloaded the crontab daemon, but I am still getting hourly reports that the file failed to launch, and the email address does not exist!
The output that is getting emailed:
/etc/cron.hourly/ntpdate:
run-parts: failed to exec /etc/cron.hourly/ntpdate: Exec format error
run-parts: /etc/cron.hourly/ntpdate exited with return code 1Currently, there is just the .placeholder hidden file in /etc/cron.hourly. I also ran crontab -l, and the only 3 jobs listed are expected to be listed, and are running about 10 minutes after this email keep arriving; so I know it is not one of those. Where can I look next to stop getting these emails?
EDIT #1
# ls -l /var/spool/cron
total 4
drwx-wx--T 2 root crontab 4096 Jan 25 2012 crontabsEDIT #2
# ls -l /var/spool/cron/crontabs/
total 4
-rw------- 1 root crontab 311 Jan 25 2012 root
# more /var/spool/cron/crontabs/root
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.4nUf85/crontab installed on Wed Jan 25 10:11:10 2012)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
2 1 * * * /etc/webmin/cron/tempdelete.pl
0 22 * * * /etc/init.d/gnugk stop
0 23 * * * /etc/init.d/gnugk startThis is on Debian Squeeze, using just cron, as far as I can tell
| Cron job still running when deleted |
From CLI, you can display and close a notification pop-up via gdbus/qdbus.
Here's how to that with gdbus:
gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify my_app_name 42 audio-card "Message" "Body" [] {} 20this will output something like:
(uint32 72,)72 being the notification ID. Now that you know the ID you can close the pop-up window with:
gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.CloseNotification 72 Now, if you need the ID later on, just write it to a file when you call Notify:
gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify my_app_name 42 audio-card "Message" "Body" [] {} 20 | sed 's/[^ ]* //; s/,.//' > /tmp/last_idand get it from there when you want to close the pop-up:
gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.CloseNotification $(cat /tmp/last_id)P.S. I'm on Gnome 3 and notifications sent via notify-send, pynotify, libnotify etc only last 5 seconds regardless of the time option (that's the default behaviour in Gnome 3, don't ask me why). Also, they don't stack up: Gnome displays only one notification at a time. So I can't test with several pop-up windows but it should work.
|
I have written a script which generates notifications like this:
notify-send -i audio-card "Transferring audio playback to speakers." \
"Audio playback has been transferred to the analog output speaker system."Is there any way to clear or to replace these notifications from the command line or from Python? Essentially, I have a script which toggles between two PulseAudio sinks and I'd like to clear previous notifications of this type to replace them with the updated text if the user toggles quickly.
| Clearing/modifying previous libnotify notifications? |
This can be done by modifying the file /usr/share/plasma/plasmoids/org.kde.plasma.notifications/contents/ui/NotificationPopup.qml. So, open it in kate:
kate /usr/share/plasma/plasmoids/org.kde.plasma.notifications/contents/ui/NotificationPopup.qmlFind the line notificationTimer.interval = notification.expireTimeout and comment/change it to
notificationTimer.interval = 1 * 1000where 1 is the number of seconds.
Test it with notify-send "your notification"
Source here.
|
The notification popups stay too long on the screen in my opinion.
How to modify the number of seconds notifications are displayed?
I see no such option in any of the notification settings.
(Kubuntu 18.04 - Plasma 5.12.7)
| Set the time of notifications in Plasma 5 |
Finally, with the help of nice people on #xmonad IRC channel, I got the solutionHere is how :
First I resized the xmobar to leave a small gap on Right side (editing xmobarrc)
position = Static { xpos = 0, ypos = 0, width = 1346, height = 20 },Use the package stalonetray
sudo pacman -S stalonetrayConfigure stalonetray with ~/.stalonetrayrc file
decorations none
transparent false
dockapp_mode none
geometry 1x1-0+0
background "#000000"
kludges force_icons_size
grow_gravity NW
icon_gravity NW
icon_size 18
sticky true
#window_strut none
window_type dock
window_layer bottom
no_shrink false
skip_taskbar trueFinally, added it to .xintrc
You can even configure it to show multiple system tray iconsThats it :)
|
I am using slack desktop client on my Arch Linux. I am using Xmonad Window manager along with the Xmobar status bar.
On other Desktop environments, for example XFCE, the Slack Desktop client shows a small Icon (System tray icons) on the status bar, which is really helpful.
( Screenshots below are of Slack on XFCE )But I like to use Xmonad with Xmobar (which looks like this -> )Is there any way to get the slack icon on xmobar?
If not, is there any good, simple and minimal status bar which I could use on Xmonad?
| System Tray Icons on Xmonad - Xmobar Or any other minimal status bar |
notify-send works like this:
notify-send [OPTION...] <SUMMARY> [BODY]Now, as you only have one (quoted) string, that's being used for the SUMMARY and the BODY is empty. Just use blank or whatever for the SUMMARY and the BODY will display the whole message (but only when you hover over the pop-up with your mouse)1:
notify-send ' ' 'd: title,up/down: zoom,w: win_to_img,</>: rotate,*: orig,Enter/0: blah blah blah'or if you prefer gdbus:
gdbus call --session --dest org.freedesktop.Notifications --object-path \
/org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify \
my_app_name 42 '' "" 'd: title, up/down: zoom, w: win_to_img, </>: rotate, \
*: orig, Enter/0: your very long message should now span over multiple lines \
and stuf blah blah blah blah whatever...' '[]' '{}' 201: this is on gnome 3, other DEs might actually display the whole message without the need to hover over it
|
Let's say I use notify-send with this long messages:
notify-send 'd: title, up/down: zoom, w: win_to_img, </>: rotate, *: orig, Enter/0: blah blah blah'But it truncates the message, showing only a part of it with no option to view the full message:With Fedora 21 I was able to view the full message (pop up at bottom with scrollbar), but not with Fedora 24.
Version of notify-send is libnotify-0.7.6-8.fc24.i686.
Is there anyway to display full messages in Fedora 24 ?
| notify-send - How to display full message when message is longer than one line? |
This is probably the urgency hint which can be set on windows. This hint is recognized by most window managers.
Most terminals can be configured to set the urgency hint when receiving a bell.
(u)xterm for example has the bellIsUrgent option and (u)rxvt has urgentOnBell.
To ring the bell in a terminal just run tput bel or echo "\a" (depending on the shell you might need to pass option -e to echo).
When using screen you have to turn off the visual bell and turn on the audible bell via vbell off in your screenrc or by pressing ctrl+a ctrl+g.
|
I'm using the dynamic window manager of suckless (dwm). I noticed that firefox is able to send nice notifications when a download has finished. See the two figuresWhen I'm on a different tag, I get this kind of notification (inverted 1 tag) upon a finished download. I'd like to use this kind of notification for my other uxterms. E.g. in case a long job has finished it should light up like above. At best, this would also work inside the GNU screen sessions that I'm using.
I'm not sure if this is a Xorg or a dwm feature. Any ideas?
EDIT: The answer of @scai is very much to the point, but lacks the full compatibility with GNU screen. In case anybody can still improve this, it'd be very much appreciated.
| What kind of notification is Firefox sending when a download has finished? |
I think you would be better off just removing libnotify and notify-send from the equation, given your stated requirements they do not provide any additional flexibility of functionality.
If you are looking for a minimal status bar, conky has a comprehensive amount of functionality, all of which can be updated in real time (depending upon how resource intensive you are prepared to accept it being).
If you wanted to tailor something specific to your setup, you could also use simple scripting and dzen.
You could also combine the two and pipe conky to dzen for your status bar; which also means that you can display icons in the bar, if that is what you are after.
There is a long conky thread on the Arch boards that has a myriad of different configurations and approaches to provide some inspiration.
For simple notifications, you could combine dzen and inotifywait (from the inotify-tools package) to achieve this. For example, I use this script to notify me when my nick is highlighted in IRC:
#!/bin/bash
dir="$HOME/Dropbox/Centurion/irssi/"while inotifywait -qqre attrib "$dir" >/dev/null 2>&1; do
echo "IRC:" "You have been pinged..." | dzen2 -p 5
done
|
I am trying to instate a more graphically minimal notification system in Arch Linux. Specifically, I've taken interest with programs such as dzen2 or conky that allow for more text-based status bars.
Is it possible to pipe notifications (as in the libnotify, notify-send ones) to a status bar made from programs like dzen2 and conky? Is there an easier or more documented approach I could try?
I currently use Openbox, but like to switch WM's once in a while, so WM-agnostic advice would be greatly appreciated.
| How do I pipe notifications into my statusbar? |
I found out myself.Trigger the notification again
Open a console, and run xwininfo to find out which process created the notification window.
Uninstall that application, and install a different one (such as notification-daemon or xfce4-notifyd)
Restart.In my case the culprit was dunst, which did not show buttons to Confirm / Deny the Bluetooth pairing.
Edit: another answer seems to be more complete (showing you the mechanism of Unity notifications).
|
I want to see which notification daemon is running. This is because I want to replace it, since it does not properly confirm the notification from blueman-applet.
I mention that I am running the i3 window manager.
| How to identify the notification daemon? |
Udev support running external programs
KERNEL=="sdb", RUN+="/usr/bin/my_program" |
My system has to auto-mount USB devices; how can I be notified when a USB device is plugged in? Where can I read more about this subject?
I would like to handle this problem via C or a shell script.
| How to be notified when a USB device was plugged in? |
This should work:
stdbuf -oL dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' |
while grep -q 'string "Spotify"'; do
date -u +%Y%M%d-%H%M%S.%N >> timestamp.txt
doneEDIT after @StéphaneChazelas comments:
stdbuf -oL dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' |
grep --line-buffered 'string "Spotify"' |
while read trash; do
stdbuf -oL date -u +%Y%M%d-%H%M%S.%N >> timestamp.txt
done+1 other answers but I keep this for completeness
|
I am attempting to write a BASH script that creates a timestamp (to be written to file) every time a certain string is found within the output of dbus-monitor (parameters specified later in post). The main purpose of my script is to save the time (including milliseconds) and date whenever a song starts playing on Spotify, as it utilizes notifications.
The following command outputs string "Spotify" whenever a song beings playing.
dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' | grep 'string "Spotify"'My attempt:
search='string "Spotify"'
found=$(dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' | grep 'string "Spotify"')while [ ${search} == ${found} ]; do
date -u +%Y%M%d-%H%M%S.%N >> timestamp.txt
doneI am assuming the reason of my code's dysfunction is that dbus-monitor continuously runs, therefore preventing the while loop from executing.
| Run command every time regex is matched, reading from stdin which does not have an EOF |
In the past I used this plugin: https://addons.mozilla.org/en-US/thunderbird/addon/firetray/
a quote from the official plugin page:display unread messages count in tray iconWorked perfectly as far as I can remember.
|
I was trying to write a script which would add a new mail icon to my system tray, but apparently Thunderbird does not support checking for new mail from the command line.
I've tried a number of plugin, but they all seem to have only a vague description. The ones I tried just modified the new mail popup.
Therefore I'm looking for a plugin which displays an icon in the system tray for unread mails. It's not necessary to display the number of unread mails, but it would be nice though.
| Thunderbird tray icon for mail notifications |
How about:
if [ "$percent" -eq 100 ] && [ "$full_flag" -eq 0 ];
then
shuttle push note Chrome "Aurora: Battery charged" "Battery is at $percent percent"
full_flag=1
fi
if [ "$percent" -lt 100 ];
then
full_flag=0
fi |
I have a Bash script that checks my laptop battery and sends me an Android notification (via shuttle, a Bash script I wrote that serves as a cli interface for the Pushbullet API). It works nicely, but it will repeatedly notify me to unplug my laptop when the battery reach 100%. Instead, I'd rather it just notify me of 100% charge once, and then that's it (i.e. continue checking but do not notify). I do, however, want it to repeatedly notify me when the battery is low, so that I remember to plug in the laptop (which is currently what it does).
I was thinking that this is possible using continue and break commands inside the loop, but I'm not sure if that's what I want (I'm not very familiar with those).
Anyway, I would appreciate suggestions as to how to best implement this using Bash. I suspect this is very simple, but I'm just not getting it for some reason.
Here is my script:
#! /bin/bashwhile true;
dopercent=$(acpi | awk '{ print $4}' | sed -e 's/%//g' | sed -e 's/,//g') if [ "$percent" -le "20" ];
then
shuttle push note Chrome "Aurora: Plug in now" "Battery is at $percent percent"
fi
if [ "$percent" -eq "100" ];
then
shuttle push note Chrome "Aurora: Battery charged" "Battery is at $percent percent"
fisleep 7m
done | Bash script: do something one time inside a loop then stop, but continue looping |
I didn't change my keyboard layout very often, but when i do it, i use (for exemple) :
setxkbmap frThere's also an option to show the current layout of your keyboard :
setxkbmap -queryresult :
rules: evdev
model: pc105
layout: fr
options: terminate:ctrl_alt_bkspConsidering this, you could do something with the notify-send command to send the layout as a notification. Something like this :
notify-send $(setxkbmap -query | grep layout) |
I have (and often change) 3 keyboard layouts on my Mint 17/Mate. I would like to see a notification on my screen when layout is changed, e.g. "Switched to English/US". I tried to do it via keyboard settings, to find a program or script to do it, but I couldn't.
The question is: are there any programs to show current layout OR is there a way to catch layout change event from X11 in user script? Any advice or guide to information would be appreciated.
Update: I've found notify-send to actually send notification, now I need to catch layout change event.
| Keyboard layout change indicator |
Systems that do not use a desktop environment usually require installing a separate notification daemon to handle notifications. It appears that you already have the dunst notification daemon installed.
To configure its appearance, you can edit ~/.config/dunst/dunstrc. If it is not available, you can create a copy from /etc/dunst/dunstrc.
You can modify many different settings such as width, height, font, background and foreground, etc.
Once you have modified the config file, you will have to restart dunst by killing the process (pkill dunst) and starting dunst again as a background process (dunst & disown $!). Generating a new notification will also usually start the dunst daemon but it is recommended to explicitly start dunst in case there are multiple notification daemons.
See man 'dunst(5)' for details on the configuration file.
|
I am running linux mint and use the notify-send command for various purposes, and of course also receive notifications from regular applications e.g. discord or MS Teams
When using Cinnamon DE, they look pretty normal, and I can even add icons to my custom notify-send calls to make it clear what is going on
However, I recently started using XMonad WM, and I'm finding that not only are the regular application notifications ugly, but my custom ones which have nice icons in them also follow that same ugly style (please excuse blurry screenshot):For example, the above notification should contain an icon as per this command:
notify-send --hint=int:transient:1 'Connecting to VPN... Check 2FA Device.' -i myiconWhere is this configured?
| How to customise the appearance of notify-send? |
Edit the file /etc/needrestart/notify.conf
Uncomment the line,
#NR_NOTIFYD_DISABLE_NOTIFY_SEND='1'So it looks like
NR_NOTIFYD_DISABLE_NOTIFY_SEND='1' |
On Debian, I am now getting these messages,Dialog reads,Relogin or restarts required! Your session is running obsolete binaries or libraries as listed below. Please consider a relogin or restart of the affected processes! bash[pids] sh[pids]How can I disable these notifications?
| How can I get these dialogs informing me that I need to restart to stop popping up? |
If you want to send a pop up message to a user logged into a Desktop Environment, have a look at notify-send.
|
In KDE, I find that if I echo something to pts/0:
me@mypc:~$ echo hello > /dev/pts/0I get a message flash sent to myself.
I'd like to make a cron job to send similar messages to myself regularly. How can I do this?
P.S. I know that Ctrl+Alt+F7 switches to the GUI, but echoing to /dev/tty7 just gives me a permission denied error.
| Pop up a message on the GUI from cron |
There used to be a lot of broken routers out there that would drop any packets with the ECN bits set. I remember trying it and experiencing this personally. This site gives you a taste of how things used to be, particularly the "8% of the internet unreachable!" link. It's of roughly the same vintage as the article you linked; as Mat pointed out, the article describes Linux 2.4, and 2.6 was released in 2003...
Even now, years later, I wouldn't be too surprised to hear of broken routers still out there given that ECN still ships disabled on major platforms (see wikipedia). So you could turn on ECN, forget about it entirely, and later be unable to visit some site without knowing why.
|
I was going through this article on iptables and there the author said that: It's important to turn off ECN (explicit congestion notification) so
that Internet communications will work properly.Why do we need to disable the ECN?
| Why should the ECN on your machine be disabled? |
You need to set XDG_RUNTIME_DIR as well. Change your crontab to this:
DISPLAY=":0.0"
XAUTHORITY="/home/nazar/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1001"
00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2
50 * * * * /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1
* * * * * /home/nazar/Documents/scripts/cron_job_test.sh # JOB_IDMake sure you change nazar to whatever your username is and 1001 to your actual UID. You can get your UID by running id -u.
And all you need in your script is:
#!/bin/bash/usr/bin/notify-send "hello" I just tested this on Arch running Cinnamon and it worked fine.
The variables are being set in the crontab, no need to export anything from the script. There's also no point in doing so, the script is being called by cron, it wouldn't export the values you need anyway.
|
I am using Linux Mint 17.
I want to be informed every 50 min, at every hour for small break.
Here is cron job:
nazar@desktop ~ $ crontab -lDISPLAY=:0.0
XAUTHORITY=/home/matrix/.Xauthority00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2
50 * * * * /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1
* * * * * /home/nazar/Documents/scripts/cron_job_test.sh # JOB_IDHere is script for /home/nazar/Documents/scripts/cron_job_test.sh:
#!/bin/bashexport DISPLAY=0.0
export XAUTHORITY=/home/matrix/.Xauthorityif [ -r "$HOME/.dbus/Xdbus" ]; then
. "$HOME/.dbus/Xdbus"
fi/usr/bin/notify-send -i "hello"This snippet of function:
if [ -r "$HOME/.dbus/Xdbus" ]; then
. "$HOME/.dbus/Xdbus"
fiChecks DBUS_SESSION_BUS_ADDRESS and uses it.
According to this answer I executed script, and now my Dbus is saved to $HOME/.dbus/Xdbus:
nazar@desktop ~ $ cat $HOME/.dbus/Xdbus
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-flm7sXd0I4,guid=df48c9c8d751d2785c5b31875661ebae
export DBUS_SESSION_BUS_ADDRESSAll should work. I couldn't find what is missed. Because notification doesn't work now.
From terminal it works fine:How to solve this issue?
SOLUTION:
Now my crontab looks as follows:
DISPLAY=":0.0"
XAUTHORITY="/home/nazar/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"
00 13 * * * /home/nazar/Documents/scripts/lunch_break_job.sh # JOB_ID_2
50 * * * * /home/nazar/Documents/scripts/pc_break.sh # JOB_ID_1
# * * * * * /home/nazar/Documents/scripts/cron_job_test.sh # JOB_IDand cron_job_test.sh looks now:
#!/bin/bash/usr/bin/notify-send -i /home/nazar/Pictures/icons/Mail.png "hello" "It is just cron test message"pc_break.sh:
#!/bin/bash/usr/bin/notify-send -i /home/nazar/Pictures/icons/download_manager.png "Break:" "Make a break for 10 min"lunch_break_job.sh:
#!/bin/bash/usr/bin/notify-send -i /home/nazar/Pictures/icons/Apple.png "Lunch: " "Please, take a lunch!" | Notify-send doesn't work at Cinnamon |
Unfortunately this seems to be a "hard" problem. In any case, I found a workaround using the Notifications Alert extension by hackedbellini.
You can color (and blink if you want) the date if there is an unread notification. It offers blacklisting or whitelisting if you want to filter which applications this works for.
|
Is there a way to add a dot to notifications from specific applications, similar to an update notification? I've switched today to Geary e-mail, and am missing a claws-mail feature that made notifications similar to these system notifications, dot wise speaking, whenever I got new mail.
I'm using Gnome 3, Debian.
To be clear, I'm talking of the dot appearing to the left of the time at the top bar. The current behavior of the mail client is to balloon the notification message, then hide it in the notification area, so I have to look for it if I missed the message.
| Adding notification "Dot" in gnome |
man wall will give you what you need.
You execute wall with either a filename, or you pipe content to it.
For example, either,
wall file.name to broadcast the content of the file file.name or
echo "Dive\!" | wall to send the message Dive!
Update: As Stephen points out in this answer, later versions of wall can send messages by simply typing,
wall message text here
and in fact, there are additional restrictions on non-root users sending the contents of files by specifying only the file name.
|
You know, I was just there, doing my things, when suddenly a terrible Broadcast message appeared!
fiatjaf@mises ~> sl
fiatjaf@mises ~> ls dotfiles/
urxvt
vim/
vimrc
fiatjaf@mises ~> cowsay good morning
______________
< good morning >
--------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
fiatjaf@mises ~>
fiatjaf@mises ~>
Broadcast message from root@mises
(/dev/pts/3) at 11:12 ...The system is going down for maintenance NOW!How can trigger a message like this from my own programs?
| How do I send a notification to all active shells, like shutdown does? |
"A package manager is working" means that something is holding a lock on /var/lib/dpkg/lock and/or/var /cache/apt/archives/lock. You can find out which process this is with the fuser command:
dennis@lightning:~$ sudo fuser /var/lib/dpkg/lock /var/cache/apt/archives/lock
/var/lib/dpkg/lock: 18049
/var/cache/apt/archives/lock: 18049
dennis@lightning:~$ cat /proc/18049/cmdline | sed -e 's/\x0/ /g'; echo
apt-get install kdenlive And because no answer is complete without a command pipeline:
cat /proc/$(sudo fuser /var/{lib/dpkg,cache/apt/archives}/lock 2>/dev/null| head -n1 | awk '{print $2}')/cmdline | sed -e 's/\x0/ /g'; echo |
I'm on Debian 6.0.5 (squeeze) and every now and then I see the following icon in the notifications area of the GNOME2 pannel: but black instead of red. It reads A package manager is working. Usually it just displays the red one after a few seconds, which is Available updates, so I assume it was just looking for updates. But sometimes that's not the case. I don't have the option to auto-install updates so that's probably not it, so I was wondering if there's a way to see which package manager is running.
Clicking on it just opens Synaptic Package Manager, but it does not says what's running.
| How can I see which package manager is running? |
You should use dunstify instead of notify-send, because first one allows you to use notification ID and replace older notifications with newer ones. Here is link to info about dunstify, and link to example of creating volume level indicator.
|
here are my notifications and I would like each notification to replace the one before it
by the way I am using dunst for my notifications | How to make dunst show repeated notifications of the same program as one single notification |
Here's a slight adaptation of @slm's answer.
You should not use locking with Maildir, and the flags and the lock colon were the wrong way around. (You would effectively create a lock file named c, rather than clone the message, so the second action would never fire.)
The f flag seems out of place.
I reversed the order of the actions; while it makes sense to deliver, then notify, from the point of view of Procmail, the notification is a secondary action which is allowed to fail, so I do that in a clone and ignore its exit status.
Finally, grouping two actions under one condition is more intuitive using braces.
:0
* ^X-Spam-Status: Yes
{
:0cWhi
| $HOME/install/bin/notify.sh
:0
Spam/
}Having said that, I also note that Procmail already generates comsat notifications out of the box. That's a legacy notification protocol, but you might be able to use it for something. Secondly, a simple notification mechanism could be built using a script which monitors your procmail.log instead. (But yeah, parsing log files sucks.)
|
I'm using procmail with Maildir/ and easy rules like the one below to save incoming emails into directories:
:0:
* ^X-Spam-Status: Yes
Spam/Now I would like a desktop notification on new emails in certain directories/rules, I know already how to handle notifications but how to tell procmail to save into a directory and execute a script?
I know I can pipe a |command but I would prefer to let procmail saving the file, then just run a script.
Having the email (headers at least) in pipe or the dir+file path as arguments would be nice, run the script asynchronous would also be nice.
update
So, based on @slm's answer that's the result:
:0 c:
* ^X-Spam-Status: Yes
Spam/:0 Whi
* ^X-Spam-Status: Yes
| $HOME/install/bin/notify.shc copy the message in the directory but goes on with next rules
I'm not using f becase that's not a filter, if the rule match I want procmail to stop here (I hope I'm not misunderstanding the manual here)
W to suppress any program failure
h to pipe only headers
i to ignore any write error to the pipe
I'm not using w because don't want to wait the script to return
I think I don't need a lock file too (no : after Whi)
update 12/5/14
In the end I've adopted exactly the solution @tripleee proposed.
Played around also with mailutils-comsatd for few minutes before give up.
.procmailrc:
COMSAT=no | procmail save into a dir and execute a script? |
You can try wall. On my KDE machine, a small panel pops up with the message sent with wall. Of course, the message also appears in all terminals, but maybe your users do not have a terminal open. Example:
echo "It is 9 o'clock and all is well." | wall |
How can I notify all online (Desktop) users from the command-line?
I know that if I want that I get notified when something is done, I just do like this:
sudo apt-get update | notify-send "apt-get update" "update finished"What should I use to notify all users (or some specific user)?
| CentOS: Alert all desktop users from command-line |
The Power thingy and the user chat bubble thingy are both the same applet called "Indicator Applet Session".
|
I've been messing around with my system too much and messed something up. I'm new to Ubuntu, but have been using linux on servers for a few years. I'm not sure of the correct terminology so I'm including screen shots to explain what is going on.
First, system specs:Ubuntu 10.4 LTS x64 Lucid
Core i7-970
Nvidia GTX 480
Dual Screen with Twinview
Nvidia proprietary dev driver 260.24 (64-bit)Now what I screwed up:
First major customization was ppa:goehle/goehle-ppa customizations for keeping evolution open after closing the main window. That worked fine until I started messing with getting hibernate working.
I never got hibernate working even after installing linux-generic-tuxonice; it gave a warning about usb09 not stopping. The only things that I have in USB are a keyboard and mouse.
Then I started getting the error:Trying to fix this, I reinstalled the Evolution customizations. The error persists and now the panel is messed up as well. I'm not getting the application icons, the menu with the chat status, or the shutdown/restart/lock screen menu.
This is what it should look like:But this is what I'm getting now:How do I get my icons back?EDIT: I found how to get my application icons back.Right-click on panel
Add to Panel ...
Notification Area.I still have not figured out what the chat bubble menu and power menu are called.
| Gnome panel missing application icons, chat bubble menu, and power menu |
If I understand your logic correctly, how about this:
while true; do
highest_cpu="$(ps -eo %C --sort -%cpu | awk 'NR==2 {print $1}')"
if [ "$highest_cpu" -gt 8 ]; then
notify-send 'CPU alert!' "$highest_cpu"
...
fi
...
doneIf you need a non-integer CPU usage threshold, the following Bash-only solution should work:
if [[ "$highest_cpu" > 9.3 ]];then
... |
I have the following script:
#!/usr/bin/env bashsleep_period=8mwhile true; do
if ps -eo %C --sort -%cpu | head -2 | awk 'NR==2 { exit !($1>8); }'; then
notify-send 'CPU alert!' '......'
xdotool key shift
fi
sleep ${sleep_period}
doneBut I don't know how to get the notification to print the % CPU value instead of '......'.
I'm using Lubuntu 13.10, fully updated.
| How to include %CPU usage in a notification? |
There is nothing more annoying than a program that makes a sound that you cannot control. If you want to give immediate feedback to something typed or clicked, use something visual. At the most basic level, the X11 equivalent to a terminal bell is function XBell(), which works over any X11 connection.
xkb added more functionality with XkbBell() and XkbForceBell() etc.
Otherwise, if you want to give notification that some background or long-term operation has changed state, use libnotify and let the user configure a notification daemon.
The gnome specification has hints where, for example, you can specify"sound-file" The path to a sound file to play when the notification pops up, or
"sound-name" A themeable named sound from the freedesktop.org sound naming specification to play when the notification pops up.But implementing hints is optional in a server. To test one out try
notify-send --hint string:sound-name:dialog-ok myheader 'my msg' |
I've managed to get myself into an argument elsewhere trying to discourage somebody from writing a library that invokes aplay in order to get a GUI program to make a simple noise: the sort of thing that on a text console would be done by \a
My understanding is that ALSA as a subsystem is fairly pervasive, and libasound.so as a client library appears to be installed on any (Linux) host capable of running a GUI-oriented program even if it doesn't have a full desktop environment (i.e. a program relies on X11 tunnelled over SSH etc.).
On the other hand, I notice https://www.gnu.org/software/emacs/manual/html_node/elisp/Desktop-Notifications.html which implies that at least Emacs is able to raise an audible alert via D-Bus, and it looks as though KDE's konsole does something similar although I've not yet looked inside the messages in detail. In those cases I don't know if it's possible to rely on the fact that there's a theme-selected default alert sound.
I've not found anything equivalent using e.g. wmctrl.
Does the community think that best practice would be to interface with ALSA via libasound, or is there in fact a better way using e.g. D-Bus or some other way of interceding with the desktop environment (Window Manager etc.)?
| Best practice for generating bell/beep in a *n*x GUI-oriented program |
I'll try to answer your question even before you update question with the details.
The Analysis
There are these states of idle in gajim:
@unique
class IdleState(IntEnum):
UNKNOWN = 0
XA = 1
AWAY = 2
AWAKE = 3You usually consider only AWAKE or AWAY. The UNKNOWN state is a generic state which is set when you don't get any result from _get_idle_monitor (see below). XA state is an extended away - screen is locked or you have a screen saver (Only for Windows, funny is that when you are on Gnome or using XScreenSaver you can't be on extended away (it is always false)).
This is how gajim decides if you are still idling:
def _get_idle_monitor(self):
if sys.platform == 'win32':
return WindowsIdleMonitor() try:
return DBusGnomeIdleMonitor()
except GLib.Error as error:
log.info('Idle time via D-Bus not available: %s', error) try:
return XssIdleMonitor()
except OSError as error:
log.info('Idle time via XScreenSaverInfo '
'not available: %s', error)Since you are probably not using Windows I'll cover the DBusGnomeIdleMonitor and XssIdleMonitor. DBusGnomeIdleMonitorIf you are using Gnome then you are probably using this part of the code. I recommend using logging on debug mode so you will get all the messages from this part of the code.
If you see this message:
except GLib.Error as error:
log.warning(
'org.gnome.Mutter.IdleMonitor.GetIdletime() failed: %s',
error)Then gajim has problems getting idle time from your environment (hard to say a reason for that - probably DBus is not working correctly). Of course, you could also see the log.info('Idle time via D-Bus not available: %s', error) message.XssIdleMonitorHere you should see the log.info('Idle time via XScreenSaverInfo not available: %s', error) message if you are using it.
This part of the code can generate OSError messages which usually happens if you r XScreenSaver or System is missing somehow a vital part of it.
The error messages you could get:
if libX11path is None:
raise OSError('libX11 could not be found.')
if libXsspath is None:
raise OSError('libXss could not be found.')
if self.dpy_p is None:
raise OSError('Could not open X Display.')
if extension == 0:
raise OSError('XScreenSaver Extension not available on display.')
if self.xss_info_p is None:
raise OSError('XScreenSaverAllocInfo: Out of Memory.')Solution
If you are using Gnome and it does not always work, I would try to install XScreenSaver perhaps that would be more reliable way to detect your activity.
|
I have set "Away after 5 minutes" in:
Gajim
-> Preferences
-> StatusThis mostly works as expected: After 5 minutes of inactivity, my status automatically changes to "Away". When I come back and move mouse, or type on keyboard, the status changes back to "Available".
But it only works 95% of the time. Sometimes, I come back, move mouse, but status does not change to "Available".
This is extremely annoying, as I have to always check whether my status has changed every time I come back.
Why does it work sometimes, but not always?
What affects this behavior?
Is this simply a bug in Gajim, or is there something on my system that I can do to fix this?
I am using Debian Buster, and gajim 1.1.2-2
Why does such a simple thing not work reliably ?
EDIT
I am using plain Openbox as my window manager, and slim as my login manager. I do have dbus daemon running.
But I don't have any Gnome/KDE/... desktop environment.
I also don't have any screensaver
| Gajim: status change from "Away" to "Available" does not work randomly? |
This probably a partial duplicate of: Run various shell commands when NUT reports a low UPS battery
The tricky part is to display the notification on the desktop, googling a bit, I found http://rogerprice.org/NUT/ConfigExamples.A5.pdf, page 71 it describes some scripts how to do that.
|
Description of the problem
I have UPS Orvaldi KC2000 (its capacity: 2000VA/1400W) and I want to setup configuration of my Debian 10 (Buster which is currently testing) to:get GUI (preferably GNOME) notifications when there is power failure and my computer is running on UPS battery (to know that I have little time to save the work and turn off the system),
automatically turn off the computer when the battery of my UPS is critically low.I hoped that this is easy with NUT (Network UPS Tools), but it turned out that there is no obvious way to meet the 1-st requirement – which is getting GUI (preferably GNOME) notifications.
What I've done to solve the problem?
I've installed NUT (provided by nut package which installs [among others] nut-server and nut-client) and I configured it by editing files residing in /etc/nut directory.
root@host:~# ls /etc/nut
nut.conf ups.conf upsd.conf upsd.users upsmon.conf upssched.confspecifically:/etc/nut/upsd.users:
[upsmon] # name of my UPS
password = my_UPS_password
actions = SET
instcmds = ALL
upsmon master/etc/nut/nut.conf:
MODE=standalone/etc/nut/ups.conf:
maxretry = 3[myups]
driver = blazer_usb
port = auto/etc/nut/upsmon.conf:
MONITOR myups@localhost 1 upsmon my_UPS_password master
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5rest of the files (/etc/nut/upsd.conf, /etc/nut/upssched.conf) have default content – /etc/nut/upsd.conf is empty and /etc/nut/upssched.conf has single line: CMDSCRIPT /bin/upssched-cmd.(I skipped the comments sections in the above listings.)
After editing above configuration files I needed to run systemctl restart nut-*. * may be overkill, but I don't remember which services need to be restarted – nut-client.service, nut-driver.service, nut-monitor.service or nut-server.service.
I also installed nut-monitor which (quote): provides nut-monitor, a GUI application to monitor UPS status. I hoped that nut-monitor has some functionality that allows to popup warning window if UPS battery is low or there is some way to configure GNOME to display status of the UPS, but unfortunately I didn't find any way to do that.
To simulate power failure I use 2 commands: upsdrvctl -t shutdown and upsmon -c fsd (which shuts down the computer).
Recently I've found that there is nut-hal-drivers package that provides GUI notifications, but:I can't find this package in Debian repository.
nut-hal-drivers package apparently doesn't work with upsmon and upsd provided by the nut package.The question
My question: how can I setup configuration of my system to popup some kind of warning (preferably popup message native for given desktop environment) if there is power failure and my computer is using UPS' battery?
| Setup NUT power failure notifications when running computer on UPS battery |
NetworkManager should be able to do this for you. From the man page:Information about networking is exported via a D-Bus interface to any
interested application, providing a rich API with which to inspect and
control network settings and operation.
NetworkManager will execute scripts in the
/etc/NetworkManager/dispatcher.d directory in alphabetical order in
response to network events....Each script receives two arguments, the first being the interface name
of the device just activated, and second an action.
Actions:...vpn-up: A VPN connection has been activated. The environment contains the connection UUID in the variable CONNECTION_UUID.
vpn-down: A VPN connection has been deactivated.So it looks like you have two routes: tie into D-Bus to listen for events and act upon them, or drop some scripts into /etc/NetworkManager/dispatcher.d/. The latter seems the path of least resistance.
|
On Ubuntu 12.04 - actually Kubuntu, but I am using NetworkManager, so the configuration should be the same - I have configured a few VPN connections.
Now, if I have a long-running up- or download, how can I ensure that all network traffic is stopped immediately and unconditionally if the VPN connection breaks off?
What I am looking for is some method of getting notified (I don't want to poll!) of the change. The rest (e.g. inserting netfilter rules) I can handle myself. I just need to find out how to get notified about a change to an established connection.
In case it matters, the configuration I am using is based on tun0. If other details are required, let me know in a comment and I'll add them to the question.What I have tried so far:configure the main LAN connection (this is inside a VM, so there is only a LAN connection) to be manual
configure the VPN to be automaticthen I figured that this isn't the route I want to take anyway, because I want to start my script/program to get notified only whenever I activate the VPN. I am not running on VPN all the time, but most of the time.
So basically I need to register for some notification as soon as a particular VPN connection is established and then get notified if something happens to it in order to tear down the main connection automatically in response.
| How can I be notified about state changes to a VPN adapter |
Old question, but for googlers:
I was having similar problems, but on a much simpler scale. I was simply trying to do
echo "Some string\nWith a bunch of chars" | osd_catWhat I found is that osd_cat seems to have some issues with either lagging detection of availability of the OSD mechanism, or input buffering problems.If the input string is too long (it varies between 7 and 11 printable characters on my system), it will hang for the delay time and then exit without ever showing anything.My issues disappeared if I used the --wait option to osd_cat.
The side effect however is that it can take more than 5 seconds for the message to appear (on my system). Any delay times you specify for osd_cat only start once the message is visible at least, but that can mean a message meant to be displayed for the default 5 seconds will take 5 seconds to show up, and then be visible for another 5 before disappearing.On a related note this seems to be a problem with all tools built on top of osd_cat as well, and none of them account for it. The list of these tools from the original author are on his page (as listed on the man page for osd_cat) at: http://ignavus.net/xosd
This includes the more common osdsh, which is what I was trying to find an alternative for, since it would intermittently display nothing on invocation, when I stumbled on osd_cat.
|
I'm writing a simple osd_cat-based utility to display messages received through libpurple (via Finch or Pidgin, for example).
As of now, this is what I have managed to create:
dbus-monitor "interface=im.pidgin.purple.PurpleInterface, member=ReceivedImMsg" | awk '/string/ && (NR%2==1) {split($0, sender, "\"") }; /string/ && (NR%2==0) {print sender[2] ": " substr($0,11) }' | osd_cat --pos=top --align=right --indent=8 -O 4 -u whiteOr split into multiple lines for enhanced reading pleasure:
dbus-monitor "interface=im.pidgin.purple.PurpleInterface, member=ReceivedImMsg"
| awk '/string/ && (NR%2==1) {split($0, sender, "\"") };
/string/ && (NR%2==0) {print sender[2] ": " substr($0,11) }'
| osd_cat --pos=top --align=right --indent=8 -O 4 -u whiteI did some experimenting, and found following to work:
yes | osd_cat
echo "text" | osd_cat
dbus-monitor | osd_cat
dbus-monitor | awk '{print $0}' | osd_cat
dbus-monitor "interface=im.pidgin.purple.PurpleInterface, member=ReceivedImMsg" | osd_catBut following do not work:
dbus-monitor | awk '{print $1 $2}' | osd_cat
dbus-monitor "interface=im.pidgin.purple.PurpleInterface, member=ReceivedImMsg" | awk '{print $0}' |osd_catI am completely lost.
| Why does the following osd_cat script fail? |
What is a notification server, and what does it serve?In general terminology, a server is a program that clients connect to in some way (whether over network or over local IPC mechanisms). The notification server is therefore a program that accepts "show a notification" requests from clients, and shows notifications on their behalf.What is a notification client, and what does it do?Any program that uses a notification server becomes a "notification client". This is again not a notification-specific term; it's about the general architecture.What is this notify-send think I can use to make a notification pop up? Is it the (well, a) client?Yes, it's a client in this case. Its purpose is mostly just so that you can make notifications pop up; apps don't run it because they can perform the same operations directly in their own process.What is a notification daemon?Exactly the same thing as a notification server.
The term 'daemon' has a somewhat different meaning; it refers to any kind of background service, whether it is a "server" or not – but in this case, the program that's responsible for showing the actual notification popups is both a server and a daemon at the same time (as it runs in background like a daemon, and accepts requests like a service).And what is the role of libnotify?It's a small library that can be used by notification clients, to abstract away the specifics of the IPC mechanism being used (as well as the differences between protocol versions). Instead of needing to know about D-Bus and interfaces, the program just does notify_notification_new(...).
(That said, many apps choose to implement the communications directly, e.g. using libdbus to make the necessary calls – it's a pretty simple protocol so both options are probably equally common.)
The protocol that's used between a client (like libnotify) and a notification server is also often misnamed "the libnotify protocol".And from the perspecitve of the user (me), is the difference between those two aesthetic? I mean, when one is running vs the other is running, I see that the notification looks differentThat is literally the difference. The idea is that each desktop environment (GNOME, KDE, etc.) would have its own notification server that would show popups tailored for that desktop environment – appearance, settings, behavior, etc.
(It might not necessarily even be a separate daemon; e.g. in GNOME and in AwesomeWM the notification service is provided by the desktop shell itself.)Incidentally, here comes the question "what are they serving?", because it looks to me that they are only waiting for some other tool to send them notifications, so that they can show them in a nice way.Yes, but "waiting for some other tool to send them notifications" is what counts as "serving" something. A service doesn't necessarily have to return some data as a result – there are plenty of services in any system that are more-or-less one-way, i.e. whose job is to do something rather than to return something.Anyway, what if I want to do custom stuff with the notifications? Say that I want to get them all and have my own shell script that, say, just appends them in a file ~/notifications. Would that mean I'm writing my own notification server? Or client? Or what?You would be writing your own "notification server" if it implements the notification protocol, i.e. the agreed-upon method by which clients communicate with it. For most Linux systems, the de facto standard is implementing the "org.freedesktop.Notifications" interface through D-Bus – if you implement it, you have a notification server.
(Though it will be really difficult to do that through a shell script, but it can be done in about 10 lines of Python or Perl, given that the interface consists of approximately two functions.)I've tried with notification-daemon first. This doesn't work just upon installing it. For a call to notify-send to be successful, one has to either launch it (it means executing /usr/lib/notification-daemon-1.0/notification-daemon) manually, autostart it somehow, or create a file at /usr/share/dbus-1/services/org.freedesktop.Notifications.service with this content
[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/lib/notification-daemon-1.0/notification-daemonThe absence of this file is deliberate, because it implies that there is only one program providing this specific service – while in reality one may have multiple desktop environments installed, each having its own notification service, and D-Bus has no mechanism to prioritize one implementation or the other.
So while many other D-Bus services are autostartable, most notification servers deliberately aren't, so that they wouldn't be chosen to be started in the "wrong" desktop environment. The desktop environment is meant to "manually" start the appropriate service, e.g. you might start it from your ~/.xinitrc if that's what you do.Then I tried dunst, but that, as soon as installed, just works, in the sense that notify-send just works. I think this is fundamentally because it starts itself upon the first call to notify-send (which means that I initally had the impression that it worked also after I had uninstalled it; that's because the dunst process was running), but how does it do that?It uses the exact same method that you described above – its package actually includes a D-Bus .service file:
$ cat /usr/share/dbus-1/services/org.knopwob.dunst.service
[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/bin/dunst
SystemdService=dunst.service
The only difference is that the actual file is not named after the service it supposedly provides (dbus-daemon doesn't enforce this requirement for "user" services).I've also given a look at statnot which seems very very skinny and without frills, but with reference to the my previous paragraph, it feels like using statnot would still mean that I would still have to write a configuration that, via the function update_text, calls into some API that xmobar or xmonad exposes. This way I would not have control on, say, how many notifications I want to show at a time.That seems to be unavoidable. If you want custom logic, then you need to write custom logic.
For example, I had once written a notification daemon that uses dzen2 as the "popup". You can implement any logic you like in the Notify() method.
|
I use ArchLinux, but this should be irrelevant, other than being the reason why I often refer to its wiki pages.
I think don't have a really clear understanding of how notifications work, and what are the "players" interacting for notifications to work:how many players are involeved?
What is a notification server, and what does it serve?
What is a notification client, and what does it do?
What is this notify-send thing I can use to make a notification pop up? Is it the (well, a) client?
What is a notification daemon?
And what is the role of libnotify?In an attempt to understand that and to set up notifications on my system, I referred to this wiki page.¹
I've tried with notification-daemon first. This doesn't work just upon installing it. For a call to notify-send to be successful, one has to either launch it (it means executing /usr/lib/notification-daemon-1.0/notification-daemon) manually, autostart it somehow, or create a file at /usr/share/dbus-1/services/org.freedesktop.Notifications.service with this content
[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/lib/notification-daemon-1.0/notification-daemonThen I tried dunst, but that, as soon as installed, just works, in the sense that notify-send just works. I think this is fundamentally because it starts itself upon the first call to notify-send (which means that I initally had the impression that it worked also after I had uninstalled it; that's because the dunst process was running), but how does it do that?
And these two, notification-daemon and dunst are both under the section Notification servers > Standalone, but they are also called "notification daemons"; does it mean that notification daemon and notification server are synonyms? If not, where's the difference?
And from the perspecitve of the user (me), is the difference between those two aesthetic? I mean, when one is running vs the other is running, I see that the notification looks different. Incidentally, here comes the question "what are they serving?", because it looks to me that they are only waiting for some other tool to send them notifications, so that they can show them in a nice way. Or are both of them doing both things? In either case, where do the notifications originally come from? How do they get to notification boxes?
Anyway, what if I want to do custom stuff with the notifications? Say that I want to get them all and have my own shell script that, say, just appends them in a file ~/notifications. Would that mean I'm writing my own notification server? Or client? Or what?
The reason I'm asking is that I want to experiment with the idea that I can show notifications in the xmobar status bar (which I use with XMonad window manager), so I'm trying to understand all the bits.
I've also given a look at statnot which seems very very skinny and without frills, but with reference to the my previous paragraph, it feels like using statnot would still mean that I would still have to write a configuration that, via the function update_text, calls into some API that xmobar or xmonad exposes. This way I would not have control on, say, how many notifications I want to show at a time.
I'm getting a bit lost :/
Trying to understand the implications on this question of mine from the Desktop Notifications Specification has been unsuccessful :D(¹) But I had a pre-existing "bug" in my ~/.xinitrc, so I had to solve that first.
| How do notifications work on linux? |
First thing, ensure that indicator support is installed on your system (packages libindicator7 and libindicator3-7).
This will enable you system to receive indicator messages.
$ sudo apt-get install libindicator7 libindicator3-7Then on Thunderbird open Tools → Add-ons. There ensure that the Extension named "Messaging Menu and Unity Launcher Integration" is enabled (it should be installed by default).
This will enable Thunderbird to send indicator messages to the system.
Finally restart Thunderbird.
This is how the badge icon appears in the default "Task Manager" (which is your case),while this is how it appears switching to the "Task Manager Icon Only" applet.In any case, note that the indicator does not count the number of unread messages, but the new messages instead (which is what you asked for). For example, here I have a lot of unread messages, but only 2 of them are new. That's why the counter indicator shows the number 2. |
I would like to see the "new messages" count number on my taskbar, like Google Mail, for example something like:
Inbox(2) - Mozilla ThunderbirdI found FireTray, but it doesn't quite work, the taskbar remains unchanged even when I have new messages:Is it possible to have count number like GMail? I am using Ubuntu 16.04.4 LTS, Xenial with KDE and Thunderbird version 52.6.0.
| "New messages" count for Thunderbird on Taskbar |
I've just found it is possible to do that with a python script connected to the local dbus server as suggested here + the gntp library.
|
I'm looking for a simple solution to forward libnotify notifications (from knotify4) to a remote growl servers (running on Windows and Android).
So far I'm only able to send remote growl notifications from the command line (using gntp-send or this python lib)
The Growl for linux implementation is only able to forward the opposite way (growl->libnotify), and does not allow remote notifications...
| How to forward libnotify to growl |
Turns out some package must have installed notify-osd. Uninstalling it fixed my issue.
sudo apt-get remove notify-osdI also made a bug report (https://bugs.launchpad.net/linuxmint/+bug/1196502)
|
I recently installed Linux Mint 15 with Cinnamon. It ran smoothly after forcing a kernel update by activating visibility of "Level 5" "dangerous packages". Later, after a post-update reboot, my notifications look like those seen in Ubuntu's Unity (Notify OSD). I have only installed things through Mint's software center or apt-get.
It doesn't seem like the notifications stack up in the taskbar applet either. I do get the ubuntu styled notifications by triggering them with notify-send. The ubuntu styled notifications also replaces the volume up/down as well as brightness up/down notifications.
How can I debug this?
| Ubuntu styled notifications in Linux Mint |
Instead of installing dunst as a service, add it to your i3 config:
Edit ~/.config/i3/config and add:
exec --no-startup-id dunst |
I use arch linux with i3wm. My notifications does not work. When I type dunst in to command line it responds whith:WARNING: No dunstrc found.When I type notify-send --icon=gtk-info Test "This is a test" or dunstify --action="replyAction,reply" "Message received" it keeps running until I kill it with crt+c while no notification shows up.
This content of /etc/X11/xinit/xinitrc.d/30-dbus.sh file:
#!/bin/bash# launches a session dbus instance
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && type dbus-launch >/dev/null; then
eval $(dbus-launch --sh-syntax --exit-with-session)
fiThis is in my journalctl:
18:57:43 arch-thinkpad systemd[562]: Starting Dunst notification daemon...
18:57:43 arch-thinkpad dunst[49939]: CRITICAL: Cannot open X11 display.
18:57:43 arch-thinkpad systemd[562]: dunst.service: Main process exited, code=exited, status=1/FAILURE
18:57:43 arch-thinkpad systemd[562]: dunst.service: Failed with result 'exit-code'.
18:57:43 arch-thinkpad systemd[562]: Failed to start Dunst notification daemon.
18:59:43 arch-thinkpad dbus-daemon[708]: [session uid=1000 pid=708] Failed to activate service 'org.freedesktop.Notifications': timed out (service_start_timeout=120000ms)
18:59:43 arch-thinkpad dbus-daemon[708]: [session uid=1000 pid=708] Activating via systemd: service name='org.freedesktop.Notifications' unit='dunst.service' requested by ':1.112' (uid=1000 pid=17718 comm="/usr/lib/electron/electron /usr/bin/caprine ")How can I fix this so programs can show notification throw dunst ?
Thank you for help
EDIT1: The No dunstrc found. error has been fiex whith this command: cp /usr/share/dunst/dunstrc ~/.config/dunst/dunstrc
| Arch linux: Notifications not working in i3wm - dunst: CRITICAL: Cannot open X11 display |
You do it the other way around:
$ pushover-notify "This is my message" command arg1 arg2Your script pushover-notify could be something like this:
#!/bin/sh
TOKEN=your_token
USER=your_user
MSG="$1"
COMMAND="$2"
shift 2
if "$COMMAND" "$@" ; then
# here run your send-message script, with message "$MSG". for example:
curl -s \
-F "token=$TOKEN" \
-F "user=$USER" \
-F "message=$MSG" \
https://api.pushover.net/1/messages
else
# here send some message indicating failure, or don't do anything. for example:
curl -s \
-F "token=$TOKEN" \
-F "user=$USER" \
-F "message=command failed: $COMMAND $@" \
https://api.pushover.net/1/messages
fi |
I was playing around with Pushover, and had the thought that it would be cool if I could use it as an argument on any random command, so that it would run a pushover script at the end of the task, regardless of what that task was.
I have no idea if it's possible, or how I would go about it, but I'd like to learn.
This question on the RasPi Stack Exchange site is what got me thinking about it. But I think there are many things it would be useful for, like letting you know when that compile job is finally finished, and maybe if it was successful.
I had the thought that it could look something like:
$ apt-get -b source packagename -pushover "Compile job complete."The thought being that the argument '-pushover [enter message text here]' after any command would execute the pushover script, and use their API to notify you via their app.
So I guess the question is, is it possible to do in this fashion? If so, where do I start? If not, are there better ways to accomplish the same thing, without being limited by what command you are running?
I'm not locked on the idea of using it as a command argument, but I do want a way to run it with any command, without writing a separate script for each one.
I am new to Linux, so if it is a non-starter idea, I'll take that answer, too, provided there are logical explanations of why it won't work to go with it.
| What would it take to add a command to run a script at the completion any given random task? |
There is old school console tool:
nethogs - Net top tool grouping bandwidth per processe.g. run in this manner:
# nethogs eth0NetHogs version 0.8.0 PID USER PROGRAM DEV SENT RECEIVED
11173 user rtorrent eth0 111.001 4.358 KB/sec
13159 user rtorrent eth0 125.673 3.734 KB/sec
9737 user irssi eth0 0.027 0.1
9687 user chromium-browser eth0 0.000 0.000 KB/secYou can browser the developer's site, for more information and more such tools.
Now you can grab the source, make your own fork and develop kind of GUI.
Appending sockets info with fidelity near bandwidth not a great job.
|
Is there a GUI to track any socket connection sent to this computer and which program that initiates it?
Also if possible track any incoming connection sent to this computer and which program that handles it (as a realtime popup indicator if possible) ?
For example:
"/bin/x owned by user x tries to connect to x.x.x.x:x"
"x.x.x.x connected to your computer on port 80 handled by /usr/bin/apache"or at minimum, what should I learn to create this kind of software?
| Linux GUI to track connections made from/to this computer |
This report indicates it's sudo apt-get install notification-daemon.
|
I'm using Ubuntu-Server 12.04, but I wasn't sure if this was an Ubuntu specific question, so I'm posting it here.
I got myself a graphical user interface by installing xinit and openbox (using apt-get install). I installed guake as well (again using apt-get install). However, when I try to run guake in my terminal emulator (Sakura), I get the following error message:
Traceback (most recent call last):
File "/usr/lib/guake/guake.py", line 1356, in <module>
if not main():
File "/usr/lib/guake/guake.py", line 1299, in main
instance = Guake()
File "/usr/lib/guake/guake.py", line 649, in __init__
notification.show()
glib.GError: GDBus.Error: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service filesHow can I fix this and get guake to run?
| Guake throws an error on startup |
notify-send is simple, all you need to do is call it from your bash script like this
notify-send 'some title' 'some message'You'll get nice little notification pupup on KDE.
|
I am using Debian with KDE. There is a small bash script, that runs in the background. If it encounters a certain condition, I want my work on a full-screen IDE or completely unrelated console windows, to be interrupted with a notification.
Once I saw an app, the sole purpose of which was to pop a window of googly eyes right in the center of the screen, but am unable to find any such now.
| Looking for a simple graphical notifier in KDE, invokable from bash |
Partial answer: as SL uses GNOME, this tells you the gconf keys for disabling at least the power management's notifcations. So in case these are your "annoying" ones...
Edit another part, I think you're done with notifications if you disable the Notification Area Applet, probably via some GUI panel options.
|
Besides:
chmod -x /usr/libexec/notification-daemon
rebootare there any solutions to turn off permanently all the annoying notification messages?
| Turn off notifications under Scientific-linux 6.1 |
Luckas' answer pointed me in the direction of a workaround (rather than a solution):
In /usr/share/plasma/plasmoids/org.kde.plasma.notifications/contents/ui/NotificationItem.qml
@@ -230,7 +230,7 @@ ColumnLayout {
// HACK RichText does not allow to specify link color and since LineEdit
// does not support StyledText, we have to inject some CSS to force the color,
// cf. QTBUG-81463 and to some extent QTBUG-80354
- text: "<style>a { color: " + PlasmaCore.Theme.linkColor + "; }</style>" + notificationItem.body
+ text: "<style>a { color: " + PlasmaCore.Theme.linkColor + "; } p { color: " + PlasmaCore.Theme.textColor + "; }</style><p>" + notificationItem.body + "</p>"
// Cannot do text !== "" because RichText adds some HTML tags even when empty
visible: notificationItem.body !== ""While this does not solve my issue properly, at least I can read my notifications again. Since it took me several hours to reach such a trivial goal (not helped by the fact I had to log out and into Plasma after every change - you'll have to do the same after this edit), I'm sufficiently happy/annoyed to stop here.
However, this workaround may give some insight into the actual problem - I'm still very interested to hear any further suggestions.
|
I am using Plasma-desktop notifications for all kinds of things, often from scripts using kdialog or notify-send. My Plasma desktop uses a dark background with a light foreground (text). Until a few months ago, all was well, but after a system update (in May?) my notifications kept their dark background but started using dark text as well for the notification body. Hence, all I can read is the title.
I looked at my current colour scheme in ~/.local/share/color-schemes/*.colors, setting all text (Foreground*=255,0,0) to red, but the notification fonts did not change. This document provides some specifications and mentions that ForegroundInactive should be used for the body text. However, this may be in a section of the colour scheme that is currently lacking. Also, the document is about three years old.
I'm using KDE Plasma v.5.25.5 on Gentoo Linux.
How can I change the colour of the (body) text in my notifications?
| How can I change the text colour in a Plasma-desktop notification? |
Try sourcing /etc/X11/xinit/xinitrc.d/50-systemd-user.sh from your xinit.
|
Whenever I run notify-send, nothing happens. When I run xfce4-notifyd-config and click preview, I get dialogues saying: Error calling StartServiceByName for org.freedesktop.Notifications:
GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process
org.freedesktop.Notifications exited with status 1and(xfce4-notifyd-config:16007): Gdk-WARNING **:
gdk_window_set_icon_list: icons too large | xfce notifications not working |
Step #1
First make sure the motion sensor box has a SSH private key set up on it: ssh-keygen.
Step #2
Then make sure the public key for said private key is on the more powerful computer. You need to put it at the end of a file with a name like this:
/home/${user}/.ssh/authorized_keysNOTE: ${user} is your user's name on the more powerful computer.
Also, make sure on the powerful computer, /home/${user}/.ssh/ has the permissions 700 (drwx------), and /home/${user}/.ssh/authorized_keys has permissions 600 (-rw-------). You can use the chmod to set permissions.
$ chmod 700 /home/${user}/.ssh/
$ chmod 600 /home/${user}/.ssh/authorized_keysStep #3
Then, from the remote sensor computer, run something like:
$ ssh user@more-powerful-computer '/usr/local/bin/process_motion_event' |
Here's an interesting situation. I have:A Linux box that is a motion sensor and can execute command line commands upon receiving a motion event (see the Linux motion app).
Another Linux box that (I would like to) dedicated to additional processing in the event that a motion is detected.The reason I don't want the first Linux box to do additional processing is that it is woefully underpowered and isn't conveniently connected to other systems that I'd like to activate.
So my question is, how do I broadcast or send machine readable code from that first Linux box to another Linux box (or any ssh client) to trigger further processing based on the type of code? I tried the broadcast command but for some reason, it shows up as empty in the clients instead of a specific code. In addition, how do I enable the 2nd Linux box to act upon the code? Should it be a cronjob or some sort of listener?
| Broadcast or send machine readable code to ssh clients |
This issue sounds suspiciously familiar to this one from Ubuntu. This bug is old, and has to do with gnome-panel. The bug in Launchpad is titled:Visual corruption affecting several panel applets.SUMMARY:
After graphical logon notification area gets scrambled. Icons are in terrible mess. Some of them are overlapping others. Sometimes network manager icon is missing. Sometimes phantom icons show up. They can be clones of any other icons in the notification area. Bug affects any graphics card: ATI, nVidia, Intel...There are 4 workarounds with this bug, which to my knowledge hasn't been resolved.Workaround #1
Run killall gnome-panel from the terminal or Gnome's "Run" dialog. The panels will automatically respawn correctly.
Workaround #2
When you get your icons distorted right-click on the affected panel (not icons) click "Properties". In "Panel Properties" change panel orientation to "Left" or "Right" and back to "Top" or "Bottom". In my case all icons are displayed properly, but one (nm-applet) is missing.
Workaround #3
Right click the Gnome panel and remove the offending applets and re-add them, i.e. Indicator Applet, etc.
Workaround #4
Right click the Gnome panel, click on Properties, Check Add Hide Buttons. and Close. Enough for now. If the error "runs" to lower panel, repeat the steps.Given you're using Mint + MATE I would suspect that this bug is still potentially in play given the code base for MATE derives from GNOME 2, which is where this bug persisted.
|
I'm using Linux Mint 16 Petra with the MATE desktop environment.
Perhaps I shouldn't have done this, but when I was adding a new application to my list of startup applications, I saw what seemed like duplicate entries, and so I removed the duplicates.
After a reboot, the notification area in my panel is now displaying incorrectly, with some icons being duplicated, and others, like my sound and network icons, not displaying at all. Here is what it looks like:I have tried uninstalling and reinstalling the Notification Area 1.6.1 applet, and manually adding applets like my sound applet, but without any impact.
How do I get my notification area back to normal?
| Why is my notifications applet displaying incorrectly? |
Functionality comparison
zenity --notification is equivalent to notify-send for the most simple cases.
For example, these two commands are equivalent:
$ zenity --notification --text=Title
$ notify-send Titleand so are these:
$ notify-send Title 'Long text message'
$ zenity --notification --text='Title\nLong text message'As you can see, the syntax for notify-send is shorter and simpler, because it is a specialised tool, while --notification is just one of the many commands available in zenity.
Differences are:notify-send has an expire-time option, which however, according to the current man page, is ignored by both Ubuntu's Osd and the Gnome shell.
zenity has a --listen option which can change the appearance of the notification without closing and reopening it: message displayed, visibility and icon can all be changed by sending appropriate strings to zenity's standard input.
setting an icon requires just --icon for notify-send while it requires --listen and icon: error command on standard input for zenity.
category and urgency are set with dedicated options in zenity, while they require a --hint option.Note that you need to explicitly kill the zenity process when using --listen, because it keeps listening on standard input even after it is closed (this is a bug, I suppose). This is not a problem for complex procedures where the notification changes dynamically, but it makes things unnecessarily complex for simple cases.
Also note that the --hint option of zenity is briefly mentioned by zenity --help-notification, but it is not mentioned in the man page.
Both category and urgency are documented in the Desktop Notifications Specification.
Alternatives
dialog and the old whiptail are possible alternatives, but I don't see any advantage in using them for notifications unless you cannot install notify-send or zenity or you are already using them for other purposes, since both have much more functionality than just notifications.
|
There is both zenity and notify-send. (on Fedora/GNOME at least, both seems to be pre-installed.)
So considering I want to show notifications, what are the differences between these too ones?
Is there anyone that is installed in more distros or so (by default)? Is the process of showing notifications any different? Is anyone maybe more compatible to some desktop environments? Is it even available on some desktop environments?
I also noticed the documentation on notify-send is pretty spare. In my Fedora installation, it does not even have a man page…
| What are the differences/(dis)advantages of zenity vs notify-send? |
As of irssi 0.8.17 it's possible to ignore ONLY activity:
/help ignoreThe special level 'NO_ACT' can be used to ignore activity in the statusbar
without actually ignoring the message; this behavior is somewhat special
because it is allowed in addition to other ignores for the same target.
Example:
/IGNORE mike NO_ACT -MSGS |
I use IRSSI (Win 8.1 x64 + cygwin + SSH to remote host, sometimes via putty instead of cygwin) and it's configured to flash taskbar button whenever there's activity in any channel or private chat.
There's a bot in one of the channels I'm in which frequently sends some information to the channel and I don't want to be notified about that. Using ignore on this bot isn't helpful because ignored lines don't get printed in the channel or save to the logs - and I still need that info.
Is it possible to disable bell/taskbar flashing ONLY for a certain channel or a single user in that channel?
| IRSSI: Disable bell on activity in certain channel |
It is very simple, hope you are asking to do thread dump when you find the string in the log.
So when you script 1 finds string in the log you need to run the thread dump script. To do so you need to include the thread dump script in the if [[ "$count" -ge 1 ]]; true block.
filelocation=$1
string=$2
count=$(cat $1 | grep -i "$2" | wc -l)if [[ "$count" -ge 1 ]];
then
echo "WARNING: There are $count occurrences of $2 in log file"
PID=$(ps -ef | grep java | awk '{print $2}')
N=3
INTERVAL=5 for ((i=1;i<=$N;i++))
do
# d=$(date +%Y%m%d-%H:%M:%S)
# dump="/tmp/Threaddump-$PID-$d.txt"
dump="/tmp/ThreadDump-`hostname`-`date '+%F-%H:%M:%S'`.gz"
echo $i of $N: $dump
/opt/jdk1.8.0_121/jdk1.7.0_40/bin/jstack -l $PID > $dump
sleep $INTERVAL
done exit 1
else
echo "OK: No lines with $2 in log file"
exit 0
fiIf you want the scrip to constantly look up the log and do the thread dump, you need to have a wrapper looping statement with 5-10 sec sleep and do this parsing and dumping logic continuously.
Code change for continuously monitoring the log.
Have a infinite loop after the file location statement, include a sleep for 60 seconds (It depends on how much sleep time you need) and end the loop in the last line. You need to do exception handling and you can demonize this script.
As mentioned by @wildcard you need to optimize for the parsing and PID part.
|
I need to write a script to create and alert and get thread dumps if a string (Related string is found) in a log file - /tmp/area.log. I am able to do this in 2 separate scripts so far but would like combine them into one.
Script 1: create an alert
filelocation=$1
string=$2
count=$(cat $1 | grep -i "$2" | wc -l)if [[ "$count" -ge 1 ]];
then
echo "WARNING: There are $count occurrences of $2 in log file"
exit 1
else
echo "OK: No lines with $2 in log file"
exit 0
fiScript 2: Create thread dumps
#!/bin/bash
PID=$(ps -ef | grep java | awk '{print $2}')
N=3
INTERVAL=5for ((i=1;i<=$N;i++))
do
# d=$(date +%Y%m%d-%H:%M:%S)
# dump="/tmp/Threaddump-$PID-$d.txt"
dump="/tmp/ThreadDump-`hostname`-`date '+%F-%H:%M:%S'`.gz"
echo $i of $N: $dump
/opt/jdk1.8.0_121/jdk1.7.0_40/bin/jstack -l $PID > $dump
sleep $INTERVAL
done | Look up a string in a log to set an alert and generate thread dumps |
No, there is no way to do this. At least not without using a GNOME Shell extension.
Here's why. GNOME, along with other desktops, uses a desktop standard from the FreeDesktop (non-)standards body. This particular standard is called Telepathy.
Essentially, Telepathy provides an abstract way of dealing with chat for desktop sessions like GNOME. So in Telepathy, a Telepathy client (like Empathy) doesn't have to care about what protocol it's talking to underneath. It just talks to Telepathy, and then Telepathy will forward on that request to some daemon that is actually responsible for speaking whatever protocol you're using. These daemons are called Telepathy providers. This all gets tied together through the magic of D-Bus.
Empathy is a Telepathy client that is a traditional "app". However, Telepathy clients don't have to be "apps" with windows and menubars and buttons and everything. They can also be, oh, I don't know... a component of a notifications system.
Yep, the input that you are seeing is actually the notifications subsystem of GNOME Shell being a Telepathy consumer. The notification isn't tied to Empathy at all: it originates from Telepathy, not Empathy.
That means that the "input notification" isn't a general framework for input in notifications. It doesn't work for arbitrary things. It only works for Telepathy, and so we arrive at the sad answer to your question... there is no way to ask for input like this from a shell script.
Perhaps look into zenity(1)?
|
When I get a chat message in Empathy, I get a notification in GNOME Shell. This notification allows me to input a reply directly, instead of having to switch to Empathy.
Is there any way I can get a similar prompt from a shell script?
| How can I receive input through notifications in bash? |
There is a patched version of notify-osd that you can use to customize all aspects of the notification bubbles, including position on the screen.
Other possible tweaks include:change font and background colors, opacity, size, corner radius
change the timeout (only works if an application specifies the timeout)
disable fade out
close the notifications on clickYou can install the application after enabling the ppa, as described here.
|
The notifications extrude the screen. I am on Ubuntu 11.10 with Gnome3.2. | Notification out of screen |
The simplest solution is to use the exit from tmux, by issuing a tmux detach, to close the ssh connection, then send a notification, and then reconnect and attach back to the tmux. Eg with the script
ssh -t remote tmux
notify-send done
ssh -t remote tmux attachYou run tmux, and start off your long-running command, then type-ahead the command
tmux detachwhich will run when the long command is done. This will close tmux, close the ssh, and the notify-send will show your desktop message. A new ssh will reattach exactly where you left off.
|
I'm connecting using OpenSSH to a Linux server where I have a tmux session where I do certain compiling work which takes a long time. Now I would like to be get right away a notification on my Linux client (the computer I'm connecting from) once a certain command which takes a long time finally is complete.
Locally, I know of several ways of how to get notified using a pop-up, playing something, … (1), (2) by running a certain command. Now I would need to do the same remotely. A perfect solution would be some sort of feedback channel right in ssh but I'm not aware of any such functionality.
And please no email-based solution as suggested in (3). I'm getting already too many work emails and I'm trying to dial down the amount of emails for something just to acknowledge but not for reading, storing, forwarding or replying to (for this I even created a separate email account for which I don't get real-time notifications).https://superuser.com/questions/345447/how-can-i-trigger-a-notification-when-a-job-process-ends
https://askubuntu.com/questions/277215/make-a-sound-once-process-is-complete
Alert when running process finishes | Notification that remote process completed (but no email) |
It seems to me that this is covered earlier in that document, in Prompting in maintainer scripts, with:Package maintainer scripts may prompt the user if necessary. Prompting must be done by communicating through a program, such as debconf, which conforms to the Debian Configuration Management Specification, version 2 or higher.
[…]
If a package has a vitally important piece of information to pass to the user (such as “don’t run me as I am, you must edit the following configuration files first or you risk your system emitting badly-formatted messages”), it should display this in the config or postinst script and prompt the user to hit return to acknowledge the message. Copyright messages do not count as vitally important (they belong in /usr/share/doc/package/copyright); neither do instructions on how to use a program (these should be in on-line documentation, where all the users can see them).
Any necessary prompting should almost always be confined to the config or postinst script. If it is done in the postinst, it should be protected with a conditional so that unnecessary prompting doesn’t happen if a package’s installation fails and the postinst is called with abort-upgrade, abort-remove or abort-deconfigure. |
I want to notify user about important details when package is installed. I've looked at https://www.debian.org/doc/debian-policy/ch-controlfields.html#list-of-fields but don't see anything fit for that purpose. Is there any way to do this?
| How to print message to the user on package installation? |
This depends on what notification deamon you are using.
If you are using dunst, which is often used with i3, you can access the history with ctrl + `
You can change the key in ~/.config/dunst/dunstrc:
# Redisplay last message(s).
# On the US keyboard layout "grave" is normally above TAB and left
# of "1". Make sure this key actually exists on your keyboard layout,
# e.g. check output of 'xmodmap -pke'
history = ctrl+grave If you are on Ubuntu using notify-osd, this may help.
|
Is it possible to see the last notifications, that were send through notify send? Sometimes, i just miss the notification and want to see it again.
| See last notifications from notify send in I3 |
Using gnome-tweak-tool, which should be available in the repositories (or installed already), you can adjust font sizes and scaling, along with some HiDPI scaling options.
There are also a few scaling options in the 'Universal Access/Accessibility' section of the Gnome settings program.
One of those should have the setting you need to adjust.
|
I'm running Pop_OS on a System 76 laptop. It's running Gnome and for some reason after re-installing the OS on a new drive, (the original SSD borked on me) the font in the notifications are HUGE! We're talking 72pt here!
Anyways after a couple hours of looking around the interwebs and poking around the system, I've found nothing!
Possible causes are from installing a Gnome extension that I removed. I've tried removing the extensions I installed. I've also tried adding and re-removing the extensions that I tried. No Luck.
Here is an image of what I'm dealing with. I'd just like to reset the notifications back to default. | Gnome notifications font size is huge. How to change? |
Deleting the file
/var/lib/PackageKit/offline-update-competedsolves it.
Solution found on Debian forum here. It looks like it is a known bug.
But it seems to be there since at least two years. And so it may happen again eventually. I hope someone knows a better solution.
(And yes by the way, there is a typo in the file name.)
Follow-up: I am no more having this issue, but I am no more acting on updates notification nor select the "install update" option when shutting down. I just let unattended-upgrade do the job instead. It sounds to me as a reliable way to avoid the trouble.
|
Since a few weeks, I get a notification after each boot telling me that important updates has been installed. Even if I dismiss it then immediately reboot, it comes again. It starts to be quite annoying.
It looks like it has started after I get a message asking me something like rebooting for installing updates (sorry, I do not remember precisely). I have done that, though not being used to it at all.
I am under Debian Jessie 8.7. My box is configured to run unattended upgrades, and it works fine since I have set it up. (That was when latest Jessie was 8.5.) It is shut down every day.
Is there any way to fix this?
| "Important updates installed" keeps popping up |
Yes, the notification setting can be restored via gsettings. The reason you didn't find the setting is because the it is not stored by Xubuntu notification daemon xfce4-notifyd.
Reset network notification
The easiest way is to reset the network notification to default setting from command line. The following one-line command will restore notification when the Internet connection is established.
In the Terminal, type the following command and press Enter key.
gsettings reset org.gnome.nm-applet disable-connected-notificationsThe effect is immediate, so restart is unnecessary.
To see the notification, click on the indicator icon for networking in the Xfce panel, then select/deselect Enable Networking option. The notification will show up again as usual.
Extra: Other network notifications
In case you accidentally pressed the Don't show this message again button for other network notifications, you can list them by running the following command.
gsettings list-keys org.gnome.nm-appletThe output will show list of keys as below.
stamp
disable-disconnected-notifications
disable-vpn-notifications
disable-connected-notifications
suppress-wireless-networks-available
show-applet
disable-wifi-createLook for relevant ones that have notifications keyword. Then run the reset command with the key you wish to reset.
gsettings reset org.gnome.nm-applet [KEY]Alternatively, you can choose to enable notification manually by running the set command with false option. Since the key names are named as disable-, the false option is correct.
gsettings set org.gnome.nm-applet [KEY] falseBoth methods have been tested working in Xubuntu 14.04.
|
My OS is Xubuntu 14.04 and if you are using it too, you've surely noticed that when internet connection is established, it gives a notification by default at the top right corner of monitor. It has a button Don't show notification and I pressed it accidentally. Now I missed the notifications so much and want it back! Does anybody know where is its setting to give it back?
I tried notifications panel in settings, but no change was observed.
| Missing connection notifications in Xubuntu |
Fixed, added a file in /usr/share/dbus-1/services/org.freedesktop.Notifications.service
with
[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/lib/notification-daemon/notification-daemonin it
|
i was working on a python script that displays notification, here's the library I'm using https://www.devdungeon.com/content/desktop-notifications-linux-python
from gi.repository import Notify
Notify.init("App Name")
Notify.Notification.new("Hi").show()it works fine when I run it without sudo but when I run it with sudo, it gives error
GLib.Error: g-dbus-error-quark: Error calling StartServiceByName for org.freedesktop.Notifications: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ExecFailed: Failed to execute program org.freedesktop.Notifications: No such file or directory (23)I'm using ubuntu 18 with gnome, can someone help?
| Ubuntu Notification Failed to execute program org.freedesktop.Notifications: No such file or directory (23) |
I'm using gnome-session 3.28.1-10.0.1.el8 and have a Notifications page in Settings that allows me to turn off all notifications or just those for a particular application. Turning them all off seems to have prevented the annoying completion messages.
|
in RHEL 7.5, or 7.6 where I am using GNOME classic 3.28,I run a tar command in a terminal window which takes a few seconds, when finished a popup happens saying command completed
and other times when I right click and do new terminal, the terminal window shows up almost immediately, but i also get a popup saying terminal window is readyI don't like those popups in gnome telling me what I already know, is there a way to disable that?
| gnome 3.28 disable ready/completed pop-up |
Through gnome-tweak-tool, you can install the topicons plus extension.
It does just that; moves the icons to the top bar, with a few options to get them just right for your setup.
Here's a direct link for you convenience: https://extensions.gnome.org/extension/1031/topicons/
|
For some of my commonly-used applications, GNOME places their notification icons into this small tray at the bottom-left of my screen.
Here's how it looks expanded:It's normally tucked away with about 1 or 2px protruding and can be expanded on click, but this has a major drawback: when it's expanded, it takes up usable screen space, covering up part of the window beneath it; when it's retracted, I can't see notifications raised by those applications.
Is there a way to move these icons into the system bar at the top of the screen, where they're permanently visible without covering usable screen space? I've looked through both the tweak tool and the dconf editor, but haven't found anything that affects this (or, at least, nothing that seems obvious by name or description, or isn't flagged as deprecated).
| In GNOME, can I move icons from the notification tray to the system bar at the top of the screen? |
Well, Gnome notifications use D-BUS to pass the messages around. The gnome specification describes how to use the org.freedesktop.Notifications.* classes and has a good deal of formatting tips. In general it is a HTML-ish format.
Yet, you absolutely cannot talk to the D-BUS on another machine remotely. Let's not even start on how many security holes that would open.
Still, you can always have a program on the target machine that will receive the communication and talk to D-BUS locally already in there.
There are two options that are wrappers around org.freedesktop.Notifications.* and make writing programs much easier:libnotify: which is almost a de-facto standard for making notifications, supports not only gnome but several others.
notify-sharp-3: as strange as it may sound it is an open-source C# based functionality around several notification specs. At some point it even had its own language called boo, but it is kind of dying out in favour of libnotify.OK, libnotify we go.
libnotify comes with a binary that knows how to talk with the notification daemon (yes, those notifications are displayed by a background daemon). The command is notify-send, and it is rather trivial to use.
notify-send 'Meeting in 5 minutes' 'John from the <b>QA Team</b> just found a bug that should never had happened. Seriously, we are doing something wrong'And that will display the notification. Yet, making it remote is a little more complex. Assuming that you know that bob is the user currently running Xorg at machine krakatoa and that krakatoa has libnotify installed and is running gnome notify daemon you can do:
ssh bob@krakatoa \
notify-send 'Meeting in 5 minutes' \
'John from the <b>QA Team</b> just found a bug that should never had happened. Seriously, we are doing something wrong'But finding each user on each machine may be tricky. You may try to create a script that will perform ps -afe | grep gnome, find the user and run su -u <user> DISPLAY=:0 notify-send .... But then again, you probably should not send ssh requests as root in the first place.
The Arch wiki has a list of interfaces to libnotify in several languages. From there you can create your own daemon, with your own communication protocol for the notification messages. For example, since you are specifically after gnome, python Gobject may just fit the bill.
In summary:Notifications happen on D-BUS;
You cannot directly access D-BUS remotely;
You can use libnotify to access D-BUS from a program under your control on the target machine.References:Gnome notifications specification
Arch wiki on desktop notifications, with examples using several languages |
I want to display my desktop notifications (I'm using Gnome 3) on some other device. So I want to write a software that gets the notification on my computer and sends it over the internet. Unfortunately, I didn't find any good point to start on how my code can get the notifications and do something with them.
Is there some API for it?
| How do I get the desktop notifications? |
There are two low level interfaces that I'm aware of:
One is simply to do a sleep() until that moment when you want to receive the notification. The sleep call is provided by glibc.
The other method would be the alarm() system call. It allows you to tell the kernel that after a defined amount of time has passed it should send the calling process a SIGALRM. It's very likely that you'll have to create an appropriate signal handler which then does what you want to do.
For both of these two approaches you can't set the absolute time when you want to get notified. Instead you will have to get the current time, and calculate based on it for how long your process has to wait until it should be awaken or alarmed.
References (on Linux):
man 3 sleep;
man 2 alarm;
|
Is there a way, in Linux or FreeBSD, to receive notification from system at a specified time? I'm thinking something in like of what inotify in Linux does for filesystem events.
There IS a way to that using cron, but I'm asking if there is a lower-level interface that can be called programatically. If cron is an 'official' Unix interface for this kind of task, I'd like to know that, too.
| Get system notification at a certain time? |
You are not getting a notification from a portable media player, you are getting a notification about one: the system identifies your phone as a portable media player and is letting you know that a portable media player (your phone) has been connected. This is very common, phones are often recognized as media players or cameras instead of phones because the system detects the media files on them.
I don't use KDE, but that looks like a standard notification for a new connected device.
It is coming from some kio job sending, via dbus, the information to the notification subsystem. But since most part of the kio thing belongs to kde-frameworks and that you are running a very old version of them (5.96 current) it will be hard to tell you more.
|
When I connect my smartphone to my Debian Linux machine, I see a popup notification from "Portable Media Player". "Who/what" is sending this notification? PMP is a common expression, so Google didn't help much.I'm using:Debian GNU/Linux 10
KDE Frameworks 5.54.0
Qt 5.11.3 (built against 5.11.3) | How to identify the application sending this notifications? |
Sure you could use 0-length timers, but if you want immediate reactions, there is also the AT ... EXECUTE syntax.
If you want pages immediately whenever the power state changes, you would use the AT <notifytype> <upsname> EXECUTE <command> syntax. In other words you could do something like this in upssched.conf:
CMDSCRIPT /usr/local/sbin/custom-upssched-cmd[...]AT ONBATT * EXECUTE start_panicking
AT ONLINE * EXECUTE panic_overAnd your /usr/local/sbin/custom-upssched-cmd script (remember to chmod a+x it!) would then contain something like this:
#!/bin/sh
case "$1" in
start_panicking)
logger -t custom-upssched-cmd "UPS went on battery power at this time"
# add here a command to send a suitably alarming pager message
;;
panic_over)
logger -t custom-upssched-cmd "UPS reports power is back"
# add here a command to send a calming pager message
;;
*)
logger -t custom-upssched-cmd "The administrator forgot to add a suitable message for upssched.conf command $1"
;;
esac |
I would like to configure NUT UPS monitoring software under Linux to simply page me when the UPS goes onto battery power, and then when it returns to line power. For example, when I receive the following messages from upsmon in syslog:
Aug 19 05:43:27 jupsden upsmon[466]: UPS jupsden@localhost on battery
Aug 19 05:43:42 jupsden upsmon[466]: UPS jupsden@localhost on line powerAnd, maybe the best solution is a custom syslog rule?
But, all of the examples I have seen for NUT-specific configured notifications in /etc/nut/upssched.conf were for starting a timer when the UPS battery level reaches a certain low threshold, then passing a custom parameter to a custom script upssched-cmd, gracefully shutting down systems, etc. Using the "timer" approach, could I do something like the following in upssched.conf:
AT ONBATT * START-TIMER onbatterypower 0
AT ONLINE * CANCEL-TIMER onlinepower...or are there some different / better NUT conf commands that would achieve what I want to do?
| NUT and immediate notifications |
This was caused by the pasystray package. It was reported on GitHub and fixed on version 0.7.1.
I had also found a report in the Manjaro forums.
|
Using Firefox 64 with Cinnamon (4.0.8) on Arch Linux.
Since upgrading to Firefox 62, I'm getting a system notification saying "input AudioIPC Server x%" whenever I start or stop playing media in Firefox.
Screenshot below:This is a bit annoying, I'd like to stop getting these without disabling notifications altogether and my search attempts were unfruitful so far.
Apparently there's no way to disable notifications for a specific application. And I'm surprised I couldn't find other people complaining about this anywhere.
Is there a solution?
| How to disable audio sink notifications from Firefox on Cinnamon? |
I've come up with the following function (to be put into ~/.bashrc):
n() {
local msg=$(tmux display-message -p '#S: #W: finished')
echo "
local n = require('naughty')
n.notify({
text = '$msg'
, preset = n.config.presets.critical
})
" | awesome-client
} |
What I'd like to achieve is as follows. Say, I run a command in tmux's window:
sleep 5; notify-meAnd I want to see a notification telling me tmux's session name and tmux's window name of what has just finished. I'm running Awesome windows manager.
I can display a notification like so:
#!/usr/bin/env bash
set -eu
echo "
local n = require('naughty')
n.notify({
text = "session 1: window 1: job's done"
, preset = n.config.presets.normal
})
" | awesome-clientI thought I could make use of tmux's alert hooks here, but I don't see a way to find out where it (alert) comes from.
| Desktop notifications of finished tasks |
I added this to my crontab and all my notifications work (currently tested with zenity and notify-send):
DISPLAY=":0.0"
XAUTHORITY="/home/me/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus |
I'm trying to use a cron job to see when the battery gets lower than a given threshold, and then to send a battery critical notification. However, when I make the cron job execute a script every minute, and make the script send me a notification, it doesn't work.
To make sure that it's not a permissions issue with the script or something causing the cron job to not run, I made the script create a file instead, and it worked. This is the crontab entry:
* * * * * /home/aravk/test.shAnd, to simplify the problem, these are the contents of test.sh:
#!/bin/sh
/usr/bin/dunstify hiNo notification shows up, however. The script does work when I execute it manually. I also tried setting the DISPLAY environment variable to :0 by changing the crontab entry to * * * * * export DISPLAY=:0 && /home/aravk/test.sh, but it still didn't work. How do I send notifications from a script executed by a cron job? I'm on Arch Linux, if it's relevant.
| Unable to send notifications from cron job |
According to the documentation, when you call scripts from a rules file, your script has access to a few environment variables. Or you can give them directly as arguments to the script you are calling.
So I guess what you want in your script is something like
if [ "$DUNST_APP_NAME" = "application1" ]; then
#...
elif [ ... ]
#...
#...
fi |
I'm trying to get Dunst to make different sounds when different applications send notifications. Dunst uses a script to play a sound when it gets a notification, this is what is currently in mine:
#!/bin/sh
paplay ~/.config/dunst/notification.oggMy idea was to use an if statement checking for the name of the application to select which sound is played, something like
#!/bin/sh
if(application1)
then
paplay ~/.config/dunst/notification1.ogg
elif(application2)
then
paplay ~/.config/dunst/notification2.ogg
else
paplay ~/.config/dunst/notification3.ogg
fi | Getting the name of the program sending notifications |
The command tr doesn't work as you intended:-d, --delete
delete characters in SET1, do not translateMeaning that tr removes single characters from the SET1, for example:
$ echo foobar | tr -d fb
ooarNow let's see man notify-send:SYNOPSIS
notify-send [OPTIONS] {summary} [body]So you have to pass 2 arguments (besides the OPTIONS). For example:
$ notify-send 'System' 'foo' 'bar'
Invalid number of options.$ notify-send 'System' 'foo'
<notification appears>Let's see the output of du -h /boot 2>/dev/null:
4,0K /boot/efi
3,4M /boot/grub/x86_64-efi
2,3M /boot/grub/fonts
8,0M /boot/grub
146M /bootYou have there 2 strings for each row! so your command results in (using /boot as example dir):
notify-send 'System' 'Dist files is already' 4,0K /bootif the output is only 1 line, but as you can see, it could be many lines. So, a bunch of arguments.When you remove the space, the resulting string is read as one, hence it looks like the correct 2 arguments.So change your command to:
notify-send 'System' "Dist files is already $(du -h /var/cache/distfiles/)"only if you are sure that output is just one line. Here an example with /root folder
$ notify-send 'System' "Dist files is already $(du -h /root 2> /dev/null)"or
$ notify-send 'System' "Dist files is already $(du -h /root | awk '{ print $1 }')" |
I'm trying to send a notification through a notify-send
notify-send 'System' 'Dist files is already' $(du -h /var/cache/distfiles/ | tr -d '/var/cache/distfiles/')But the spacer that I need cannot be displayed for some unknown to me reason, it outputs:
Invalid number of options.But If I'll remove the spacer in there like this:
notify-send 'System' 'Dist files is already'$(du -h /var/cache/distfiles/ | tr -d '/var/cache/distfiles/')It would works perfectly. Please, explain to me why is that so, I'm too dumb.
| Problem with a spacer |
To disable Web push notifications for a site in Firefox :
Click on the "i" (left of the green lock on the address bar).
Open permissions preferences.
Notifications/Settings
Block the website
|
I accidentally subscribed to news notifications from a stock market site and now I am getting notifications every few minutes that are irritating me.
I do get other notifications for email I'd like to keep. How can I find which alerts are active on my system and turn them off? Or failing that, turn them all off.
I am working on a Linux Mint 17.3 system, it is my own (I have the root password).
P.S. The Zacks.com site has an alert area, but it says I am not subscribed. I thought this was the site, but the alerts don't show who they are from, and I was surfing other market sites yesterday, too. So I'd just like to know how to look at a list, or if getting rid of cookies would work, or something like that.
| How to turn off a notification coming from a website? |
Based on the comments to the question, I found
Why can't I run Gnome apps over remote SSH session?
Two of the answers (not the accepted one, but that is older, and might work too, just not be the easiest way any longer) there mentioned dbus-launch. And if I run dbus-launch notify-send "Hello world", the notification does appear on the screen of my laptop.
|
I have two computers, a desktop and a laptop, both running Debian Stretch.
Desktop notifications works on the laptop, and I believe it works (the attached
monitor is broken, so I can't check, and maybe I should say "used to work").
On the laptop I run i3 as wm, no desktop environment, and dunst as notification
daemon.
I have no problems logging in to the desktop using SSH from the laptop. X forwarding also works, but desktop notifications aren't forwarded.
If I run notify-send "Hello world" on the laptop, I get a notification saying "Hello world", if I run the same command on the desktop (through a SSH connection, where I can start X programs, so X forwarding is enabled and working) nothing happens. One program that tries to send notifications, outputs:
** (transmission-gtk:21556): CRITICAL **: gtr_notify_torrent_completed: assertion 'G_IS_DBUS_PROXY (proxy)' failedwhen it tries.
How can I make desktop notifications get forwarded?
| Forwarding desktop notifications over SSH |
Thanks to @Gilles' hints, I put together something that flashes the command window when there is a bell in a visible session. To do this I wrote a quick bash script:
#!/bin/bash
#flash console as a visible bell
#requires installation of xcalibxcalib -i -a
sleep 0.01
xcalib -i -aand entered the full path to this script under "Run command" for "Bell in Visible Session" in the konsole "Configure Notifications" dialog.
|
I would like to set up my terminal to use a visible bell notification. Konsole is my preferred terminal emulator, but I can't seem to figure this out.
Everything I can find on the web points me towards set bell-style visible in .bashrc, or towards Settings->Configure Notifications. The bash setting seems to have no effect, and under configure notifications, none of the options corresponds to a visible bell.P.S. for extra credit, if anyone knows why konsole started ignoring the characters "s" and "v" from either keyboard or clipboard when I tried the following in bashrc, I can add that as a separate question: bind bell-style visible
| Does konsole support a visible bell? |
You should specify the environment variable: DBUS_SESSION_BUS_ADDRESS in your systemd service and use RemainAfterExit=yes in the section [Service].
In my case, I used echo $DBUS_SESSION_BUS_ADDRESS to get its value:
echo $DBUS_SESSION_BUS_ADDRESS
#output:
unix:path=/run/user/1000/busSo the systemd service would be:
[Unit]
Description=should run node app which launch a desktop notification
After=network.target[Service]
Environment="DISPLAY=:0" "XAUTHORITY=/home/myuser/.Xauthority" "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"
Type=simple
User=myuser
RemainAfterExit=yes
ExecStart=/home/myuser/.nvm/versions/node/v16.13.1/bin/node /home/myuser/notify_send/notify_node/build/index.js
Restart=on-failure[Install]
WantedBy=multi-user.targetSince you are running: /home/myuser/.nvm/versions/node/v16.13.1/bin/node /home/myuser/notify_send/notify_node/build/index.js from your systemd service I think you could get some errors (because of dependencies, but I'm not really sure, I do not know much about node) so I suggest you create a script under /home/myuser/notify_send/notify_node/build like this:
runApp
#!/bin/bashcd "$(dirname $(realpath $0))"node ./index.js &>/home/user/logsSystemd service
[Unit]
Description=should run node app which launch a desktop notification
After=network.target[Service]
Environment="DISPLAY=:0" "XAUTHORITY=/home/myuser/.Xauthority" "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"
Type=simple
User=myuser
RemainAfterExit=yes
ExecStart=/home/myuser/notify_send/notify_node/build/runApp
Restart=on-failure[Install]
WantedBy=multi-user.targetInstead of using cron-jobs in your node app you can use Systemd Timers whose have more features
|
Based on my previous searches, I think that the answer is that I can't do that, but anyway I would like to ask because I'm not a linux pro. I have a small app made with nodejs that launch a desktop notification every second:
import notifier from 'node-notifier'
import {CronJob} from 'cron';/* Create a cron job that send a desktop notification every second */
const job = new CronJob('* * * * * *', () => { notifier.notify({
title: 'My notification',
message: 'Hello, there!',
});
}, null, true, 'America/Los_Angeles');job.start()This works well when I run npm run start. I want to run this using a systemd service:
[Unit]
Description=should run node app which launch a desktop notification
After=network.target[Service]
Environment="DISPLAY=:0" "XAUTHORITY=/home/myuser/.Xauthority"
Type=simple
User=myuser
ExecStart=/home/myuser/.nvm/versions/node/v16.13.1/bin/node /home/myuser/notify_send/notify_node/build/index.js
Restart=on-failure[Install]
WantedBy=multi-user.targetSeveral seconds after start the service, the status command shows this:
● runjs.service - should run node app which launch a desktop notification
Loaded: loaded (/etc/systemd/system/runjs.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2022-12-04 17:47:40 CET; 22s ago
Main PID: 5606 (node)
Tasks: 20 (limit: 18651)
Memory: 18.1M
CGroup: /system.slice/runjs.service
├─5606 /home/myuser/.nvm/versions/node/v16.13.1/bin/node /home/myuser/notify_send/notify_node/build/index.js
├─5633 /bin/sh -c notify-send "My notification" "Hello, there!" --expire-time "10000"
├─5634 notify-send My notification Hello, there! --expire-time 10000
├─5639 dbus-launch --autolaunch=017e96ffe51b466384d899f21cbecdc5 --binary-syntax --close-stderr
├─5640 /usr/bin/dbus-daemon --syslog-only --fork --print-pid 5 --print-address 7 --session
├─5642 /usr/bin/dbus-daemon --syslog-only --fork --print-pid 5 --print-address 7 --session
└─5643 /usr/bin/plasma_waitforname org.freedesktop.Notificationsdic 04 17:47:40 slimbook systemd[1]: Started should run node app which launch a desktop notification.
dic 04 17:48:00 slimbook dbus-daemon[5640]: [session uid=1000 pid=5638] AppArmor D-Bus mediation is enabled
dic 04 17:48:00 slimbook dbus-daemon[5640]: [session uid=1000 pid=5638] Activating service name='org.freedesktop.Notifications' requested by ':1.0>But no desktop notification is launched when service is running.
Thanks in advance.Edit
After doing changes suggested by @edgar-magallon, add additional information:
$ sudo systemctl status runjs.service
● runjs.service - should run node app which launch a desktop notification
Loaded: loaded (/etc/systemd/system/runjs.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2022-12-24 00:26:59 CET; 4s ago
Process: 3281 ExecStart=/home/user/notify_send/notify_node/build/runApp (code=exited, status=127)
Main PID: 3281 (code=exited, status=127)dic 24 00:26:59 slimbook systemd[1]: runjs.service: Scheduled restart job, restart counter is at 5.
dic 24 00:26:59 slimbook systemd[1]: Stopped should run node app which launch a desktop notification.
dic 24 00:26:59 slimbook systemd[1]: runjs.service: Start request repeated too quickly.
dic 24 00:26:59 slimbook systemd[1]: runjs.service: Failed with result 'exit-code'.
dic 24 00:26:59 slimbook systemd[1]: Failed to start should run node app which launch a desktop notification.and the logs:
$ sudo journalctl -xeu runjs.service
-- Support: http://www.ubuntu.com/support
-- Support: http://www.ubuntu.com/support
--
-- The unit runjs.service has entered the 'failed' state with result 'exit-code'.
dic 24 00:26:59 slimbook systemd[1]: runjs.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Automatic restarting of the unit runjs.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
dic 24 00:26:59 slimbook systemd[1]: Stopped should run node app which launch a desktop notification.
-- Subject: A stop job for unit runjs.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit runjs.service has finished.
--
-- The job identifier is 2072 and the job result is done.
dic 24 00:26:59 slimbook systemd[1]: runjs.service: Start request repeated too quickly.
dic 24 00:26:59 slimbook systemd[1]: runjs.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit runjs.service has entered the 'failed' state with result 'exit-code'.
dic 24 00:26:59 slimbook systemd[1]: Failed to start should run node app which launch a desktop notification.
-- Subject: A start job for unit runjs.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit runjs.service has finished with a failure.
--
-- The job identifier is 2072 and the job result is failed.What am I doing wrong?
| How to run a node app which launch a desktop notifications using systemd service |
I figured it out!
The trick was to open the osdWindows.js file and find the following lines:
this._icon = new St.Icon();
this.actor.add(this.icon, { expand: true });and comment out the second line. Then I discovered that while this does remove the icons, it does not resize the osd window, so I then found the following lines in the _monitorsChanged function, and edited the following lines:
this.actor.set_size(this._popupSize, this._popupSize);
this.actor.translation_y = (monitor.height + monitor.y) - (this._popupSize + (50 * scaleFactor));
this.actor.translation_x = ((monitor.width / 2) + monitor.x) - (this._popupSize / 2); and edited them to this:
let popupWidth = 200;
let popupHeight = 50;
this.actor.set_size(popupWidth,popupHeight);
this.actor.translation_y = monitor.height-3*popupHeight;
this.actor.translation_x = ((monitor.width / 2)-(popupWidth / 2));This resized the osd windows, as well as performs some repositioning, since I changed the layout a bit.
|
I am working on customizing the look of my desktop with the cinnamon.css file in a custom theme that I am working on for Linux Mint, and I came across the osdWindow class in the file, and was able to change the background-color, border-radius, etc. of the volume and brightness osd notifications.
But I was wondering how I might customize the look of it, for example, I would like the osd window to still popup when the volume is changed, but I would like to be able to remove the icon from the popup, or change its layout. I have looked over the osdWindow.js file, and I believe that this would be the place to do it, but I do not know how.
Can anyone help me with figuring this out?
| How to customize the osd windows in cinnamon? |
If you want a notify popup holding the final summary line, something like
sent 6,673,231 bytes received 17,718 bytes 13,381,898.00 bytes/sec
total size is 6,613,892 speedup is 0.99then you can capture the rsync output into a file, and use the last 2 lines of the file:
rsync ... | tee /tmp/out
notify-send "$(tail -2 /tmp/out)"If you would like a more detailed summary, add --info=stats2
rsync --info=stats2 ... | tee /tmp/out
notify-send "$(tail -16 /tmp/out)"This will provide extra info such as:
Number of files: 932 (reg: 929, dir: 2, link: 1)
Number of created files: 932 (reg: 929, dir: 2, link: 1)
Number of deleted files: 0
Number of regular files transferred: 929
Total file size: 6,613,892 bytes
Total transferred file size: 6,613,888 bytes
Literal data: 6,613,888 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 6,673,231
Total bytes received: 17,686 |
I'm using rsync to push some changes to a server, for that I made a bash script and I want to show a status notification in the desktop (I'm using Linux Mint 18 Cinnamon)
Is it possible to send the output of rsync to notify-send so I can see the amount of data synchronized? Here is my actual bash script:
notify-send "sincronizando esteticas"
rsync -tprvkku --exclude "00_docs" --exclude "temp" --exclude "config.php" --progress public_html/ rsync://myserver:/myfiles
notify-send "sincronizacion terminada" | bash : send rsync status using notify-send |
This is easy enough to set up using the fnotify script. Set it to autoload and then customise it to print to a file of your choosing:
sub filewrite {
my ($text) = @_;
# FIXME: there is probably a better way to get the irssi-dir...
open(FILE,">>$ENV{HOME}/path/to/your/fnotified");
print FILE $text . "\n";
close (FILE);
}
Then, use inotifywait to watch that directory or file, and trigger a message when new lines are written to it:
#!/usr/bin/env bash
# script to push IRC highlight notificationsdir="$HOME/path/to/your/"while inotifywait -qqre attrib "$dir" >/dev/null 2>&1; do
echo "IRC:" "You have been pinged..." | notify-send IRC "You have been pinged…" \
-i /usr/share/icons/gnome/48x48/status/dialog-warning.png
done
I run irssi on a headless server, so I sync the watched directory to all of the other machines I use with Pulse, (formerly Syncthing), and then run the inotify script on those local machines so that, wherever I am logged on, I will get notified if I am pinged...
You can run the inotify script from a service file if you use systemd or however you would like to start it on login.
If you don't want to use notify-send, dzen is an excellent choice for an unobtrusive notification application.
|
I want to get a notification each time I get a /query message or get highlighted in a channel.
this notification should be in the form of bubble OSD (on screen Display).
If OSD isn't possible for Linux, I'll settle for bringing the terminal window containing the irssi instance to the top of the window stack and flickering window's name in status bar.
| OSD notification for Irssi |
In a modern distribution with a non-exotic configuration this is already happening, see the output of journalctl -xe
You can parse it with something like the command below to get something easier to read:
journalctl -e | perl -ne 'print "\"$1\" ran \"$2\" with sudo\n" if(/.*sudo.*?\:\s*(\S+).*COMMAND=(.*)/);' |
I'm just learning Linux for educational purposes, but, I am really enjoying this operation system.
For a homework I have to implement a system that contains something that the users can see as the safest when managing a server, so, I'd want to configure something like:
If a user with root permission needs to install a software or a lib, when typing sudo xxxx command the manager of a team (Information security regularly) must receive a notification that user john is installing the software xxxx.
Does someone knows if this is possible?
For now my lab is running in Ubuntu
| Need to monitor sudo permission |
The UI on these notifications changed a few days ago. (I do an apt update; apt upgrade every night.) The notification box now has a place you can click (I forget if it was a tiny gear icon or what) to block notifications from this source (in my case bostonglobe.com). I still don't know the answer to my question, but my need to know has vanished.
| I subscribe to the Boston Globe. I get unwanted news alerts from them as desktop notifications. I never asked for them. I don't want them. I contacted the Boston Globe and they won't help me. I logged on to bostonglobe.com and looked for a relevant setting - no luck. I get many desktop notifications. I only want to stop the ones from the Globe. I know how to programmatically throw up a notification, but I have no idea how to turn off or block specific notifications. And I would like to continue my Globe subscription. I'm running Pop!_OS 20.04 LTS and I login to i3 window manager. Thanks in advance.
| How to block specific desktop notifications? [closed] |
Sadly, no. This function is responsible for deciding if events sent from wpa_supplicant to wpa_cli are written to the interactive terminal.
static int wpa_cli_show_event(const char *event)
{
const char *start; start = os_strchr(event, '>');
if (start == NULL)
return 1; start++;
/*
* Skip BSS added/removed events since they can be relatively frequent
* and are likely of not much use for an interactive user.
*/
if (str_starts(start, WPA_EVENT_BSS_ADDED) ||
str_starts(start, WPA_EVENT_BSS_REMOVED))
return 0; return 1;
}The only events that are not written are WPA_EVENT_BSS_ADDED and WPA_EVENT_BSS_REMOVED (which is good because they can happen hundreds of times when a scan is executed). Fastest way to stop this message from printing in your interactive terminal would be to modify the if statement to
...
if (str_starts(start, WPA_EVENT_BSS_ADDED) ||
str_starts(start, WPA_EVENT_BSS_REMOVED) ||
str_starts(start, WPS_EVENT_AP_AVAILABLE))
...You could also add in any other messages you find annoying - the macros are defined here.
|
Is it possible to deactivate wpa_cli notifications/messages like <3>WPS_AP_AVAILABLE? Because it spams it, and in a VT where you have to slowly type MACs@ and bssIDs, it's really hard with those bothering messages
| Deactivate wpa_cli notifications |
The mintupdate refresh the apt cache periodically and display the available packages upgrade, that's why you get a notification every 3-5 hours (the default is 2 hours, you can adjust it from the mintupdate preferences). It is a good feature to keep the system up-to-date.
When you receive a notification, you can upgrade your packages, by executing the following command (without executing sudo apt update because it is already done by mintupdate ):
sudo apt upgradeor
sudo mintupdate-cli upgradeSee: man mintupdate
Linux Mint Update Manager explained
|
I use Linux Mint. Every 3-5 hours I see a new update notificaton. I have no probelm installing them, but just from curiosity, why do I get them that often? Is it a regular thing? Should I worry about it?
| Too much notifications for updates in Mint |
First try list the open files if you can diagnose , which display the user too along with which program does that.
lsof /path/file-nameCheck out these for more details :
Check which process modify file
| There's a process in my system (a standard desktop installation with upwards of 150 quiescent processes at any time) that is sporadically resetting a config file's permissions that I have explicitly set so that it could be read by multiple users.
Even though I have ways to prevent that from happening (eg, changing the file's owner), I really want to find the process that is doing the change, if only so that I can terminate it with extreme prejudice.
I know the kernel has at least 2 mechanisms for this, inotify and the more recent fanotify. However, the latter only intercepts changes to file contents, not to the inode, while the former does detect such changes but doesn't report the process responsible.
So is there another kernel mechanism which i don't know about? Or some other roundabout way of "trapping" the process as it's going to change the file's permissions, or after it has done so?
| How to find which running process is modifying a file's permissions (Linux)? [duplicate] |
Completely untested:
/path/to/catalina.sh 2>&1 | while IFS= read -r line; do
echo "$line"
if [[ $line == *"Server startup in"* ]]; then
dialog --msgbox "$message" 10 40
fi
done |
I would like to display a dialog box using zenity or dialog or something similar based on a specific string displayed in console window?
Background:
I have created a wrapper shell script which calls Tomcat 7 catalina.sh. I want to display a info box with a OK message when "Server startup in XXXXXms" is outputted to the console. I dont want to edit the catalina.sh as its prone to changes or overwritting. So I need to do this in wrapper shell script.
Is the above possible?
Thanks
| Create dialog based on console output |
If your browser is Google Chrome, you may get rid of gnome-keyring in it.
Just switch to internal Chrome password storage with --password-store=basic on Google Chrome start:
/usr/bin/google-chrome-stable --password-store=basic |
Whenever I visit any Index page of any website, it pops up with this notification.I'm using Kali GNU/Linux Rolling.
| how to remove the popup notification of keyring login? |
As ipor-sircer noted, it was an extra notification daemon called dunst that was installed. I started getting regular notifications again after I have uninstalled it, logged out and logged in.
|
I am on BunsenLabs (debian jessie 8.2). One day the notifications started looking like this.I don't remember messing with anything to with notification themes. If I select these options from the notification options, nothing happens.How do I reset or fix this?
| How do I reset notification themes? |
Try this:
# modprobe pcspkr
# echo -e "\a" >/dev/consoleIf you didn't hear a sound... Are we sure you do have a piezo speaker in there?
Otherwise, continue with loading pcspkr on boot:
# echo pcspkr >>/etc/modules | I have a quite long Bash script I use to install Apache server environments including PHPmyadmin and several other utilities, after logging to the remote machine via SSH. I run the script via the Ubuntu server 16.04 CLI terminal.
When the script runs, it stops sometimes, about 5-6 times to ask for password (whether in Unix itself or in some installation programs it starts).
Is there a way to make sure a sound notification will be played in each such stop whether in Unix itself or when a new installation program is initiated?Update for SYN:
I did:
82 sudo apt install alsa-utils
83 speaker-test -t sine -f 1000 -l 1And got:
speaker-test 1.1.0Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Sine wave rate is 1000.0000Hz
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4771:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM default
Playback open error: -2,No such file or directory | Sound indicator for when a script temporarily stops? For example, to fill in data or passwords? [duplicate] |
bash
In bash, that's probably as good as it gets. That uses a shell builtin. If you need the result in a variable, you could use command substitution, or the bash specific (though now also supported by zsh):
printf -v int %.0f "$float"You could do:
float=1.23
int=${float%.*}But that would remove the fractional part instead of giving you the nearest integer and that wouldn't work for values of $float like 1.2e9 or .12 for instance.
Also note the possible limitations due to the internal representation of floats:
$ printf '%.0f\n' 1e50
100000000000000007629769841091887003294964970946560You do get an integer, but chances are that you won't be able to use that integer anywhere.
Also, as noted by @BinaryZebra, in several printf implementations (bash, ksh93, yash, not zsh, dash or older version of GNU printf), it is affected by the locale (the decimal separator which could be ., , or ٫).
So, if your floats are always expressed with the period as the decimal separator and you want it to be treated as such by printf regardless of the locale of the user invoking your script, you'd need to fix the locale to C:
LC_ALL=C printf '%.0f' "$float"With yash, you can also do:
printf '%.0f' "$(($float))"(see below).
POSIX
printf "%.0f\n" 1.1is not POSIX as %f is not required to be supported by POSIX.
POSIXly, you can do:
f2i() {
LC_ALL=C awk -- '
BEGIN {
for (i = 1; i < ARGC; i++)
printf "%.0f\n", ARGV[i]
}' "$@"
}Note that though literal numbers in the awk language syntax are always using the . as decimal radix character (as , is used to separate arguments so couldn't be used in numbers), when taking numbers on input like here from ARGV, some implementations honour the locale's decimal radix character. In the case of GNU awk, that's only when $POSIXLY_CORRECT is in the environment.
zsh
In zsh (which supports floating point arithmetic (decimal separator is always the period)), you have the rint() math function to give you the nearest integer as a float (like in C) and int() to give you an integer from a float (like in awk). So you can do:
$ zmodload zsh/mathfunc
$ i=$(( int(rint(1.234e2)) ))
$ echo $i
123Or:
$ integer i=$(( rint(5.678e2) ))
$ echo $i
568However note that while doubles can represent very large numbers, integers are much more limited.
$ printf '%.0f\n' 1e123
999999999999999977709969731404129670057984297594921577392083322662491290889839886077866558841507631684757522070951350501376
$ echo $((int(1e123)))
-9223372036854775808ksh93
ksh93 was the first Bourne-like shell to support floating point arithmetic. ksh93 optimises command substitution by not using a pipe or forking when the commands are only builtin commands. So
i=$(printf '%.0f' "$f")doesn't fork. Or even better:
i=${ printf '%.0f' "$f"; }which doesn't fork either but also doesn't go all the trouble of creating a fake subshell environment.
You can also do:
i=$(( rint(f) ))But beware of:
$ echo "$(( rint(1e18) ))"
1000000000000000000
$ echo "$(( rint(1e19) ))"
1e+19You could also do:
integer i=$(( rint(f) ))But like for zsh:
$ integer i=1e18
$ echo "$i"
1000000000000000000
$ integer i=1e19
$ echo "$i"
-9223372036854775808Beware that ksh93 floating point arithmetic honour the decimal separator setting in the locale (even though , is otherwise a math operator ($((1,2)) would be 6/5 in a French/German... locale, and the same as $((1, 2)), that is 2 in an English locale).
yash
yash also supports floating point arithmetic but doesn't have math functions like ksh93/zsh's rint(). You can convert a number to integer though by using the binary or operator for instance (also works in zsh but not in ksh93). Note however that it truncates the decimal part, it doesn't give you the nearest integer:
$ echo "$(( 0.237e2 | 0 ))"
23
$ echo "$(( 1e19 | 0 ))"
-9223372036854775808yash honours the locale's decimal separator on output, but not for the floating point literal constants in its arithmetic expressions, which can cause surprises:
$ LC_ALL=fr_FR.UTF-8 ./yash -c 'a=$((1e-2)); echo $(($a + 1))'
./yash: arithmetic: `,' is not a valid number or operatorIt's good in a way in that you can use floating point constants in your scripts that use the period and not have to worry that it will stop working in other locales, but still be able to deal with the numbers as expressed by the user as long as you remember to do:
var=$((10.3)) # and not var=10.3
... "$((a + 0.1))" # and not "$(($a + 0.1))".printf '%.0f\n' "$((10.3))" # and not printf '%.0f\n' 10.3 |
Is this the right way to do float to integer conversion in bash? Is there any other method?
flotToint() {
printf "%.0f\n" "$@"
} | How to convert floating point number to integer? |
You can compare just two numbers with dc like:
dc -e "[$1]sM $2d $1<Mp"... where "$1" is your max value and "$2" is the number you would print if it is lesser than "$1". That also requires GNU dc - but you can do the same thing portably like:
dc <<MAX
[$1]sM $2d $1<Mp
MAXIn both of the above cases you can set the precision to something other than 0 (the default) like ${desired_precision}k. For both it is also imperative that you verify that both values are definitely numbers because dc can make system() calls w/ the ! operator.
With the following little script (and the next) you should verify the input as well - like grep -v \!|dc or something to robustly handle arbitrary input. You should also know that dc interprets negative numbers with a _ prefix rather than a - prefix - because the latter is the subtraction operator.
Aside from that, with this script dc will read in as many sequential \newline separated numbers as you would care to provide it, and print for each either your $max value or the input, depending on which is the lesser of the wo:
dc -e "${max}sm
[ z 0=? d lm<M p s0 lTx ]ST
[ ? z 0!=T q ]S?
[ s0 lm ]SM lTx"So... each of those [ square bracketed ] expanses is a dc string object that is Saved each to its respective array - any one of T, ?, or M. Besides some few other things dc might do with a string, it can also execute one as a macro. If you arrange it right a fully functioning little dc script is assembled simply enough.
dc works on a stack. All input objects are stacked each upon the last - each new input object pushing the last top object and all objects below it down on the stack by one as it is added. Most references to an object are to the top stack value, and most references pop that top of stack (which pulls all objects below it up by one).
Besides the main stack, there are also (at least) 256 arrays and each array element comes with a stack all its own. I don't use much of that here. I just store the strings as mentioned so I can load them when wanted and execute them conditionally, and I store $max's value in the top of the m array.
Anyway, this little bit of dc does, largely, what your shell-script does. It does use the GNU-ism -e option - as dc generally takes its parameters from standard-in - but you could do the same like:
echo "$script" | cat - /dev/tty | dc...if $script looked like the above bit.
It works like:lTx - This loads and executes the macro stored in the top of T (for test, I guess - I usually pick those names arbitrarily).
z 0=? - Test then tests the stack depth w/ z and, if the stack is empty (read: holds 0 objects) it calls the ? macro.
? z0!=T q - The ? macro is named for the ? dc builtin command which reads a line of input from stdin, but I also added another z stack depth test to it, so that it can quit the whole little program if it pulls in a blank line or hits EOF. But if it does !not and instead successfully populates the stack, it calls Test again.
d lm<M - Test will then duplicate the top of stack and compare it to $max (as stored in m). If m is the lesser value, dc calls the M macro.
s0 lm - M just pops the top of stack and dumps it to the dummy scalar 0 - just a cheap way of popping the stack. It also loads m again before returning to Test.
p - This means that if m is less than the current top of stack, then m replaces it (the duplicate of it, anyway) and is here printed, else it does not and whatever the input was is printed instead.
s0 - Afterward (because p doesn't pop the stack) we dump the top of stack into 0 again, and then...
lTx - recursively load Test once more then execute it again.So you could run this little snippet and interactively type numbers at your terminal and dc would print back at you either the number you entered or the value of $max if the number you typed was larger. It would also accept any file (such as a pipe) as standard input. It will continue the read/compare/print loop until it encounters a blank line or EOF.
Some notes about this though - I wrote this just to emulate the behavior in your shell function, so it only robustly handles the one number per line. dc can, however, handle as many space separated numbers per line as you would care to throw at it. However, because of its stack the last number on a line winds up being the first it operates on, and so, as written, dc would print its output in reverse if you printed/typed more than one number per line at it.The proper way to handle that is to store up a line in an array, then to work it.
Like this:
dc -e "${max}sm
[ d lm<M la 1+ d sa :a z0!=A ]SA
[ la d ;ap s0 1- d sa 0!=P ]SP
[ ? z 0=q lAx lPx l?x ]S?
[q]Sq [ s0 lm ]SM 0sa l?x"But... I don't know if I want to explain that in quite as much depth. Suffice it to say that as dc reads in each value on the stack it stores either its value or $max's value in an indexed array, and, once it detects the stack is once again empty, it then prints each indexed object before attempting to read another line of input.
And so, while the first script does...
10 15 20 25 30 ##my input line
20
20
20
15
10 ##see what I mean?The second does:
10 15 20 25 30 ##my input line
10 ##that's better
15
20
20 ##$max is 20 for both examples
20You can handle floats of arbitrary precision if you first set it with the k command. And you can alter the input or output radices independently - which can sometimes be useful for reasons you might not expect. For example:
echo 100000o 10p|dc
00010...which first sets dc's output radix to 100000 then prints 10.
|
I was looking for a command to limit numbers read in from stdin.
I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, simple and (I think) common use case.
My script which finds the minimum of two numbers:
#!/bin/bash
# $1 limit[ -z "$1" ] && { echo "Needs a limit as first argument." >&2; exit 1; }read numberif [ "$number" -gt "$1" ]; then
echo "$1"
else
echo "$number"
fi | Is there a unix command that gives the minimum/maximum of two numbers? |
I don't know if it is beautiful, but it is working for every version format I know.
#!/bin/bash
currentver="$(gcc -dumpversion)"
requiredver="5.0.0"
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]; then
echo "Greater than or equal to ${requiredver}"
else
echo "Less than ${requiredver}"
fi(Note: better version by the user 'wildcard': https://unix.stackexchange.com/users/135943/wildcard , removed additional condition)
|
Suppose I want to compare gcc version to see whether the system has the minimum version installed or not.
To check the gcc version, I executed the following
gcc --version | head -n1 | cut -d" " -f4The output was
4.8.5So, I wrote a simple if statement to check this version against some other value
if [ "$(gcc --version | head -n1 | cut -d" " -f4)" -lt 5.0.0 ]; then
echo "Less than 5.0.0"
else
echo "Greater than 5.0.0"
fiBut it throws an error:
[: integer expression expected: 4.8.5I understood my mistake that I was using strings to compare and the -lt requires integer. So, is there any other way to compare the versions?
| How to compare a program's version in a shell script? |
The test command, also named [, has separate operators for string comparisons and integer comparisons:INTEGER1 -eq INTEGER2
INTEGER1 is equal to INTEGER2vsSTRING1 = STRING2
the strings are equalandSTRING1 != STRING2
the strings are not equalSince your data is not strictly an integer, your test needs to use the string comparison operator. The last realization in the comments was that the "-eq" logic did not match the sense of the if/else echo statements, so the new snippet should be:
...
if [ "$x" != "$y" ]
then
echo There is version $y update
else
echo Version $x is the latest version
fi |
I am making the check for update script for my theme
I have 2 text files. First one is called "current.txt" and contains the current version. There is 4.1.1 string in that text file.
Second one is called "latest.txt" and contains the latest version. There is 4.2 string in this text file.
So here is the code
echo "Checking update";
x=$(cat ./current.txt)
y=$(cat ./latest.txt)
if [ "$x" -eq "$y" ]
then
echo There is version $y update
else
echo Version $x is the latest version
fiWhat it mean is if current.txt is NOT the same with latest.txt then it will say "there is version 4.2 update". If not, it will say "version 4.1.1 is the latest version"
But when I try to run it. I get this error
Checking update
./test.sh: line 4: [: 4.1.1: integer expression expected
Version 4.1.1 is the latest versionSo what am I doing wrong with this?
| Bash - Integer expression expected |
With gawk (GNU awk) for the asort() function:
gawk -v SEP='*' '{ i=0; split($0, arr, SEP); len=asort(arr);
while ( ++i<=len ){ printf("%s%s", i>1?SEP:"", arr[i]) };
print ""
}' infilereplace * as the field separator in SEP='*' with your delimiter.You can also do with the following command in case of a single line (because it's better leave it alone of using shell-loops for text-processing purposes)
tr '.' '\n' <<<"$aline" | sort -n | paste -sd'.' -replace dots . with your delimiter.
add -u to the sort command above to remove the duplicates.
Notes:
You may need to use -g, --general-numeric-sort option of sort instead of -n, --numeric-sort to handle any class of numbers (integer, float, scientific, Hexadecimal, etc).
$ aline='2e-18,6.01e-17,1.4,-4,0xB000,0xB001,23,-3.e+11'
$ tr ',' '\n' <<<"$aline" |sort -g | paste -sd',' -
-3.e+11,-4,2e-18,6.01e-17,1.4,23,0xB000,0xB001In awk no need change, it still will handling those.
|
I have a line (or many lines) of numbers that are delimited by an arbitrary character. What UNIX tools can I use to sort each line's items numerically, retaining the delimiter?
Examples include:list of numbers; input: 10 50 23 42; sorted: 10 23 42 50
IP address; input: 10.1.200.42; sorted: 1.10.42.200
CSV; input: 1,100,330,42; sorted: 1,42,100,330
pipe-delimited; input: 400|500|404; sorted: 400|404|500Since the delimiter is arbitrary, feel free to provide (or extend) an Answer using a single-character delimiter of your choosing.
| How can I numerically sort a single line of delimited items? |
The leading 0 causes Bash to interpret the value as an octal value; 012 octal is 10 decimal, so you get 11.
To force the use of decimal, add 10# (as long as the number has no leading sign):
BN=10#$(cat Build.number)
echo $((++BN)) > Build.numberTo print the number using at least three digits, use printf:
printf "%.3d\n" $((++BN)) > Build.number |
I have a file in the name of Build.number with the content value 012 which I need to increment by +1.
So, I tried this
BN=$($cat Build.number)
BN=$(($BN+1))
echo $BN >Build.numberbut here I am getting the value 11 when I am expecting 013.
Can anyone help me?
| How to increment the value of a (decimal) variable (with leading zero) by +1? |
You can; you just need to break the range {0..F} into two separate ranges {0..9} and {A..F}:
$ printf '%s\n' {{0..9},{A..F}}{{0..9},{A..F}}
00
01
...
FE
EF |
I would like to know if there is a way of using bash expansion to view all possibilities of combination for a number of digits in hexadecimal. I can expand in binaries
In base 2:
echo {0..1}{0..1}{0..1}Which gives back:
000 001 010 011 100 101 110 111In base 10:
echo {0..9}{0..9}Which gives back:
00 01 02...99But in hexadecimal:
echo {0..F}Just repeat:
{0..F} | Bash expansion hexadecimal |
awk -v n=10 -v seed="$RANDOM" 'BEGIN { srand(seed); for (i=0; i<n; ++i) printf("%.4f\n", rand()) }'This will output n random numbers (ten in the example) in the range [0,1) with four decimal digits. It uses the rand() function in awk (not in standard awk but implemented by most common awk implementations) which returns a random value in that range. The random number generator is seeded by the shell's $RANDOM variable.
When an awk program only has BEGIN blocks (and no other code blocks), awk will not try to read input from its standard input stream.
On any OpenBSD system (or system that has the same jot utility, originally in 4.2BSD), the following will generate 10 random number as specified:
jot -p 4 -r 10 0 1 |
Is it possible to generate real random numbers with a specific precision and in a specific range using the Integer Random Generator $RANDOM?
For example how we can generate real number with 4 precision between 0 and 1?
0.1234
0.0309
0.9001
0.0000
1.0000A simple workaround:
printf "%d04.%d04\n" $RANDOM $RANDOM | Bash: How to generate random float number using $RANDOM |
With awk:
awk '$1 == "1" { print; x++ } END { print x, "total matches" }' inputfile | I have a file of genomic data with tag counts, I want to know how many are represented once:
$ grep "^1" file |wc -lincludes all lines beginning with 1, so it includes tags represented 10 times, 11, times, 100 times, 1245 times, etc. How do I do this?
Current format
79 TGCAG.....
1 TGCAG.....
1257 TGCAG.....
1 TGCAG......I only want the lines that are:
1 TGCAG.....So it cannot include the lines beginning with 1257. NOTE: The file above is tab delimited.
| Grep lines starting with 1, but not 10, 11, 100 etc [duplicate] |
You can convert it to binary, reverse the bytes, optionally remove trailing newlines rev <2.24, and convert it back:
$ xxd -revert -plain <<< 030201 | LC_ALL=C rev | tr -d '\n' | xxd -plain
010203Using
$ bash --version | head -n1
GNU bash, version 4.3.42(1)-release (x86_64-redhat-linux-gnu)
$ xxd -version
xxd V1.10 27oct98 by Juergen Weigert
$ rev --version
rev from util-linux 2.28.2This does not work if the string contains 00 (the NUL byte), because rev will truncate the output at that point, or 0a (newline), because rev reverses each line rather than the entire output.
|
Is there a simple command to reverse an hexadecimal number?
For example, given the hexadecimal number:
030201The output should be:
010203Using the rev command, I get the following:
102030Update
$ bash --version | head -n1
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
$ xxd -version
xxd V1.10 27oct98 by Juergen Weigert
$ rev --version
rev from util-linux 2.20.1 | Reverse a hexadecimal number in bash |
bash cannot do floating point math, but you can fake it for things like this if you don't need a lot of precision:
$ number=248
$ echo $(( number*80/100 ))
198 | how to calculate percentage from number
for example we set
number=248and we want to know what is the 80% from $number
so how to calculate it in bash ?
expected output 198 ( exactly is 198.4 but we want to round down with floor )
| bash + how to calculate percentage from number [duplicate] |
If using GNU sort or compatible, you can use its -g switch to do a general numeric sort:
$ sort -g -k5,5 file
name: yyy --- time: 3.2 seconds
name: xxx --- time: 5.4 seconds
name: zzz --- time: 6.4 secondsThe -k5,5 tells sort to perform the sort on just the 5th column.
Usage
Keep in mind the details from the info sort page:'-g'
'--general-numeric-sort'
'--sort=general-numeric'
Sort numerically, converting a prefix of each line to a long
double-precision floating point number. *Note Floating point::.
Do not report overflow, underflow, or conversion errors. Use the
following collating sequence: * Lines that do not start with numbers (all considered to be
equal).
* NaNs ("Not a Number" values, in IEEE floating point
arithmetic) in a consistent but machine-dependent order.
* Minus infinity.
* Finite numbers in ascending numeric order (with -0 and +0
equal).
* Plus infinity. Use this option only if there is no alternative; it is much slower
than '--numeric-sort' ('-n') and it can lose information when
converting to floating point. |
I've such a file:
name: xxx --- time: 5.4 seconds
name: yyy --- time: 3.2 seconds
name: zzz --- time: 6.4 seconds
...Now I want to sort this file by these float numbers to generate a new file as below:
name: yyy --- time: 3.2 seconds
name: xxx --- time: 5.4 seconds
name: zzz --- time: 6.4 seconds
...I've tried the command awk '{print $5}' myfile | sort -g but this will show me ONLY the float numbers.
| How to sort lines by float number |
This is basic task many tools can solve; paste + awk combo seems exceptionally handy:
$ paste file1 file2 | awk '{$0=$1+$2}1'
7
9
11
13
15 |
I have a txt file that contains some numbers like this:
1
2
3
4
5 And I have another txt file that contains the same number of lines, but with other numbers:
6
7
8
9
10I want to add them together, namely 1+6, 2+7, 3+8, etc.. How do I write the script?
By the way, I've got a variety of answers so far, and only after I tried them on my files did I realise some of the methods can't deal with decimals. Some of my files contain decimals, and I need to be accurate, so if you would like to add an answer, could you show a method that can calculate decimals accurately. Thanks.
| How do I add numbers from two txt files with Bash? |
If your system uses GNU coreutils then the numfmt command should be available, and allows you to choose between rounding ‘up’, ‘down’, ‘from-zero’ (the default), ‘towards-zero’, or ‘nearest’.
For example (here in a locale where the decimal radix character is .):
$ numfmt --round=nearest --format %.2f << EOF
3.314
3.315
8.124
8.125
EOF
3.31
3.32
8.12
8.13 |
I spent hours in searching how to round "floating numbers" in BASH but couldn't find any correct! solution :( If I put these numbers to Excel, then I will receive the correct results after rounding to 2 decimals:
3.314 -> 3.31
3.315 -> 3.32
8.124 -> 8.12
8.125 -> 8.13How to have the exact results in BASH? I tried with printf and awk but don't have the same result
prompt> printf '%.*f\n' 2 8.125
8.12
prompt> echo '8.125' | awk '{printf("%.2f\n", $1)}'
8.12 | How to round to 2 decimals in bash like MS Excel does? |