You are not logged in.

#1 2013-02-04 14:33:28

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

[SOLVED] Bash Script checking for mail

I have come up with this forsaken script...

#!/bin/bash

while :
do
        NEWMAIL=$(curl -su "You'd wish." https://mail.google.com/mail/feed/atom | grep fullcount | cut -d ">" -f 2 | cut -d "<" -f 1)
        echo $NEWMAIL
        notify-send "Gmail" "You have $NEWMAIL new mails!"
        sleep 10s
done

It does get the number of new mails perfectly fine - I'm sure there is a better method with cut... -, and it echos the number, but notify-send does not seem to work. From what I've read I need to set the environmental variable or something like that. Yeah, no clue. Any hint is appreciated.

Last edited by ThunderRush (2013-02-05 14:38:15)

Offline

#2 2013-02-04 17:17:11

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,557
Website

Re: [SOLVED] Bash Script checking for mail

awk is a better choice for your text processing; we would need sample output to give more specific pointers.

export your DISPLAY before notify-send.


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#3 2013-02-04 17:50:13

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

Re: [SOLVED] Bash Script checking for mail

I will read the man to awk later.

So, I added

export $DISPLAY

before the loop, and I get this in return:

/scripts/gmailcheck: Zeile 3: export: `:0': Ist kein gültiger Bezeichner.

I guess it means "Is not a valid designator/identifier."

Google does not really help with that.

Offline

#4 2013-02-04 17:55:23

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,557
Website

Re: [SOLVED] Bash Script checking for mail

X is running, isn't it?

echo $DISPLAY
DISPLAY=:0 notify-send "GMail" "New mailz..."

Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#5 2013-02-04 18:24:46

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

Re: [SOLVED] Bash Script checking for mail

Of course I do, yes. Gnome3.

DISPLY=:0 notify-send "Test" "Test"

Works when I type it my terminal, but once again not from the script.
And Echo $DISPLAY returns :0

Offline

#6 2013-02-04 19:04:11

knopwob
Member
From: Hannover, Germany
Registered: 2010-01-30
Posts: 237
Website

Re: [SOLVED] Bash Script checking for mail

ThunderRush wrote:

I will read the man to awk later.

So, I added

export $DISPLAY

before the loop, and I get this in return:

/scripts/gmailcheck: Zeile 3: export: `:0': Ist kein gültiger Bezeichner.

I guess it means "Is not a valid designator/identifier."

Google does not really help with that.

export DISPLAY

Your version will get expanded like this

export $DISPLAY
->
export :0

which caused your error message, because ':0' is not valid in this context.

In other words, you're trying to export the content of the variable instead of the variable itself.

Offline

#7 2013-02-04 20:59:49

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

Re: [SOLVED] Bash Script checking for mail

Thank you, knopwob, that fixed the errormessage, but not the missing notify.

I really have no clue why it does not work.
Do you need any configs files, etc? I really kinda want to get over that problem so I can work on some other scripts including that.

Thanks to anyone who helped until now and anyone who will help.

Offline

#8 2013-02-04 21:00:37

benmills
Member
From: Chicago, IL
Registered: 2013-01-11
Posts: 6
Website

Re: [SOLVED] Bash Script checking for mail

I've been working on a similar script and ran into a problem where the Gmail ATOM feed only included the 20 most recent items. I'm still looking for an accurate way to check the current count of unread messages in my gmail inbox and send notifications.

Offline

#9 2013-02-04 21:02:36

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,557
Website

Re: [SOLVED] Bash Script checking for mail

Are you running this as a cron job?


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#10 2013-02-04 21:31:44

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

Re: [SOLVED] Bash Script checking for mail

I have not tried that, I currently run the script directly, and it should be in ~/.config/autostart once it works.

Offline

#11 2013-02-04 22:03:42

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,557
Website

Re: [SOLVED] Bash Script checking for mail

The script works fine here...

It may have something to do with how Gnome handles sessions, but I don't use or understand DEs, sorry.


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#12 2013-02-05 08:54:35

aesiris
Member
Registered: 2012-02-25
Posts: 94

Re: [SOLVED] Bash Script checking for mail

Maybe you need to export also the DBUS session.

In KDE I use this to notify from a root cronjob:

for pid in $(/usr/bin/pgrep 'startkde'); do
    eval $(grep -z '^USER=' /proc/$pid/environ)
    eval export $(grep -z '^DISPLAY=' /proc/$pid/environ)
    eval export $(grep -z '^DBUS_SESSION_BUS_ADDRESS=' /proc/$pid/environ)
    sudo -u "$USER" /usr/bin/notify-send -i folder-tar "test" "test"
done

Offline

#13 2013-02-05 13:26:17

ThunderRush
Member
From: Austria
Registered: 2013-01-31
Posts: 22

Re: [SOLVED] Bash Script checking for mail

I tried that aesiris, of course with some gnome things, but it did not work either.
And for jason: It's okay, thank you again for your help.

I will see what else I can do, and will post a solution if I find one - which I doubt.
What other alternatives to notify-send are there? Not a whole popup, but something more subtle?

#EDIT
As always, my own stupidity.

Since I had absolutely no right set on the file, since the password is there in clear text, ist had the Permissions 111.
But - gnome did not belong to my root.

 ps aux | grep gnome

And I always started it as sudo, as root. So I changed the ownership to my user...

sudo chown thunderuser gmailcheck

and set the rights to 500. So I can execute and read it.
And it finally worked. Thanks again.

Last edited by ThunderRush (2013-02-05 14:37:53)

Offline

Board footer

Powered by FluxBB