notify-send doesn't work in crontab (doesn't send a notification) - bash

I want to make a little script which send me a notification when an update is available for pacman. I did that :
#!/bin/sh
while /usr/bin/inotifywait -e create /var/lib/pacman; do
/usr/bin/notify-send "pacmauto" "Updating...";
updateDone=0
while /usr/bin/inotifywait -e delete /var/lib/pacman -t 30; do
updateDone=1;
done
if [ $updateDone -eq 1 ]; then
/usr/bin/notify-send "pacmauto" "Update done, you can install it with pacman -Su";
fi
done
But the fact is when i use it with my user prompt, it works. But when i want to put it in a crontab, it doesn't send me a notification when it's done. Someone can help me ?

So finally, I follow this topic (http://ubuntuforums.org/showthread.php?t=1533494) and it works now. Thanks you Philibobby !

Related

I am looking for help trying to create a .sh file to run steam games through wines windows player

I have a computer running Ubuntu with retropie (emulationstation) which i can create .sh files to run linux based steam games through as they can be directly installed onto the computer. I have installed wine in order to play the windows based games and while I can run the files by going into windows steam and clicking play, I am looking for a way to create a .sh file that will allow me to play them through retropie. I can post some of the stuff ive tried i just am struggling with the formatting.
Let me know if i need to post anything else or fix something!
EDIT: Heres some of the code ive tried, the first i thinks should run the executable through wine but i cant get anything to output, the second is some code i found online which watches for the game to close as well so it can exit clean.
#!/bin/bash
wine ~/PlayOnLinux\'s\ virtual\ drives/Steam/drive_c/Program\
Files/Steam/steamapps/common/MortalKombat_KompleteEdition/DiscContentPC/MKKE.exe
#! /bin/bash
appid=$1
procname=$2
PREFIX=/home/rig-cade/PlayOnLinux\'s\ virtual\ drives
STEAM="/home/rig-cade/.wine-steam/drive_c/Program Files/Steam/Steam.exe"
export WINEDEBUG=-all
export WINEPREFIX=$PREFIX
if [[ ((`pgrep -f steam.exe -c` == 0)) && ((`pgrep -f Steam.exe -c` == 0)) ]]; then
optirun wine "$STEAM" -silent &
sleep 20
fi
echo "Running game"
wine "$STEAM" steam://rungameid/$appid &
sleep 15
echo "Starting checks"
status=`pgrep -f $procname -c`
if (( "$status" > 1 )); then
while (( "$status" > 1 )); do
sleep 5
status=`pgrep -f $procname -c`
done
wine "$STEAM" -shutdown &
fi
echo "Exiting"
I'm not 100% sure and I will test once I get done with work in a couple hours, but AFAIK the Steam URL protocol cannot be used with the command-line and so when you try this Steam is likely throwing a parsing error. If you add -console after -silent it should enable the Console tab and allow you to see an error message if you open the client.
Instead try one of
Only using the browser protocol without the "$STEAM" part so it's not trying to pass it as an argument to the client.
Using the Steam Command-line parameter -applaunch {appid},
where {appid} is replaced with the appid of the game to be run as you were already trying to do.

Bash : check if ssh key connection is well setup

First, I'm sorry if this post duplicate another one. But if it does, I did not find it through my research :)
The problem is :
I need to check if I can connect to a server via ssh without using a password. I know you need to make a key to do so, but I just want to check if it was well done in bash.
I found a lot of things about how to test availability of the server, etc ... but not what I was searching for.
Thanks in advance for your answer ;)
T.F.
I found a solution after a new try ^^ (yeah, short time between post and solution ;) )
echo -e "Checking if you have setup a key for serve ssh connection ..."
ssh -o BatchMode=yes uname#host 'exit'
if [ $? -eq 0 ]
then
echo -e "You're done"
else
echo -e "Set up a ssh key please "
fi

Pentaho generic error handling script

At this moment I am trying to make a generic error handling script using Pentaho. So far I've found some information about Shell scripts but they do not seem to work for me.
What I want to create is a script (Shell or whatever) that can send messages through Gmail or Hipchat with information about the error and what went wrong. This has to be a generic step so that it can easily be placed in any other job.
Does anyone have ideas? I can't find much (dated) information about Pentaho at all through Google.
I have also tried sending E-mail but for some reason I just get an E-mail containing what was done, not with the errors I get?
The shell script I found is listed below, however it does not seem to be sending E-mail:
#!/bin/sh
OUTDIR=/pentaho/spoon/data-integration/Backup/FCP_DEL_ALL.out
v_jobfile=/pentaho/spoon/data-integration/production_reports/XYZ.kjb
/pentaho/spoon/data-integration/kitchen.sh \
-file="$v_jobfile" -level=Minimal > $OUTDIR
if [ $? -eq 0 ];
then
echo "The Program Completed Successfully(KAAS) :-" >> $OUTDIR
else
mail -s "TRF NAME ERROR" mick.vanhulst#gmail.com -c mick.vanhulst#gmail.com < /pentaho/spoon/data-integration/Backup/FCP_DEL_ALL.out
fi
Try setting the level to Error. By this way, only error messages would be written to log file. Also, use -log option. Also, instead of checking return code of kitchen.sh, check whether log file is empty.
OUTDIR=/pentaho/spoon/data-integration/Backup/FCP_DEL_ALL.out
v_jobfile=/pentaho/spoon/data-integration/production_reports/XYZ.kjb
/pentaho/spoon/data-integration/kitchen.sh \
-file="$v_jobfile" -level=Error -log="$OUT_DIR"
if [ -z "$OUTDIR" ];
then
echo "The Program Completed Successfully(KAAS) :-" >> $OUTDIR
else
mail -s "TRF NAME ERROR" mick.vanhulst#gmail.com -c mick.vanhulst#gmail.com < /pentaho/spoon/data-integration/Backup/FCP_DEL_ALL.out
fi

wmii configuration script for Pidgin notification

I am new to wmii. Could anybody kind enough to share his configuration script with a nice status bar that could display notifications from Pidgin?
OK, I got the notification work for Pidgin.
First, 'command-notification' plugin from Pidgin site, download
Then configure the plugin execute a shell script, like this:
#!/bin/bash
owins=$(wmiir ls /client | grep -v -e 'sel')
for owin in $owins; do
wincount=$(wmiir read /client/$owin/props | grep -c -e "Pidgin:Pidgin")
if [ $wincount != 0 ]; then
wmiir xwrite /client/$owin/ctl Urgent off
wmiir xwrite /client/$owin/ctl Urgent on
wmiir xwrite /event Notice "You have new message!"
fi
done

checking if a streaming server is up using bash?

I use Ubuntu and am trying to write a script that makes the following:
-test if an audio stream works
-if not, send an email.
I have tried the following code (running as a cron job every 10 minutes), which 'works' if I supply the wrong pw e.g.(it sends an email then), but does nothing if the actual server is down (tested by killing the server). any ideas on how to fix the script?
Thanks in advance!
#!/bin/bash
#servertest.sh
username=user1
password=xyz
url="http://wwww.streamingaudioserver.com -passwd $password -user $username"
mplayer $url &
sleep 5
test=$(pgrep -c mplayer)
if [ $test = 0 ]; then
#server is down!
mailfile="downmail.txt"
/usr/sbin/ssmtp test#maildomain.com < "/home/test/$mailfile"
fi
killall mplayer
sleep 5
exit
Your problem is in this line:
$mailfile="downmail.txt"
remove the dollar sign and that should do it.
You should be getting error messages in your cron log or emails to the crontab owner complaining about a command not found or no such file.
Edit:
Does your script work if run from the command line (with the stream down) rather than cron?
Try using set -x (or #!/bin/bash -x) in the script to turn on tracing or use echo "PID: $$, value of \$test: $test" > /tmp/script.out after the assignment to see if you're getting the zero you're expecting.
Also, try an ssmtp command outside the if to make sure it's working (but I think you already said it is under some circumstances).
Try your script without ever starting mplayer.

Resources