You are not logged in.

#1 2016-09-09 11:54:02

rexdrive
Member
Registered: 2016-09-09
Posts: 8

[SOLVED] Cron not working for one of the scripts

Any help is much appreciated.

These are the steps I followed to setup 'cronie' on my fresh installation of Arch:

1. Installed 'cronie' using the command:

sudo pacman -S cronie

2. Enabled 'cronie' on startup:

sudo systemctl enable cronie.service

3.  Started 'cronie':

sudo systemctl start cronie.service

4. Rebooted Arch.

5. Added cronjob using the command:

crontab -e

- Contents of my cron:

SHELL=/bin/bash
*/1     *       *       *       *       $HOME/scripts/system/battery.sh
*/1     *       *       *       *       $HOME/scripts/conky/wifi-state.sh

  - Contents of each script:

   - battery.sh (Obtained from Arch Forum)

#!/bin/bash

BATTINFO=`acpi -b`

if [[ `echo $BATTINFO | grep Discharging` && `echo $BATTINFO | cut -f 5 -d " "` < 00:30:00 ]] ; then
   DISPLAY=:0.0 /usr/bin/notify-send -u critical "LOW BATTERY. PLEASE HIBERNATE." "$BATTINFO"
fi

exit 0

   - wifi-state.sh

#!/bin/bash

wget -q --spider www.google.com

if [[ "$?" != 0 ]]; then
       echo Li > $HOME/scripts/conky/wifi-state;
else
        echo '' > $HOME/scripts/conky/wifi-state;
fi

exit 0

Observations:
1. The 'wifi-state.sh' script runs flawlessly.
2. 'battery-state.sh' doesn't run at all.

Questions:
1. Why does the 'battery.sh' script not run from cron even though the script runs just fine from the terminal?
2. I am a newbie here, so are there anything I am doing wrong because of which my script is not running?
3. What can I do to solve my problem?

Thanks!

Last edited by rexdrive (2016-09-09 13:12:40)

Offline

#2 2016-09-09 12:47:06

toz
Member
Registered: 2011-10-28
Posts: 506

Re: [SOLVED] Cron not working for one of the scripts

notify-send also needs access to your DBUS_SESSION_BUS_ADDRESS. Assuming that your UID is 1000:

DISPLAY=:0.0 DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" /usr/bin/notify-send -u critical "LOW BATTERY. PLEASE HIBERNATE."

For more info: https://wiki.archlinux.org/index.php/De … ifications

Last edited by toz (2016-09-09 12:48:45)

Offline

#3 2016-09-09 13:12:04

rexdrive
Member
Registered: 2016-09-09
Posts: 8

Re: [SOLVED] Cron not working for one of the scripts

toz wrote:

notify-send also needs access to your DBUS_SESSION_BUS_ADDRESS. Assuming that your UID is 1000:

DISPLAY=:0.0 DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus" /usr/bin/notify-send -u critical "LOW BATTERY. PLEASE HIBERNATE."

For more info: https://wiki.archlinux.org/index.php/De … ifications

THANK YOU SOOO SOOO SOOO MUCH!

Offline

Board footer

Powered by FluxBB