1
#!/bin/bash

ddd=$(date +%Y-%m -d "-1 month")
xmessage  -timeout 10 $ddd

If I try this simple script I get this to work fine from terminal but when I start this script via cron the variable is always empty? I have tried many different syntax but the result is the same. Works in Terminal but not from cron.

Zanna
  • 72,312
Peter
  • 11

1 Answers1

1

man date says:

SYNOPSIS
       date [OPTION]... [+FORMAT]

It should work either way, but you're on the safe side using date the way the manpage tells you:

ddd=$(date -d "-1 month" +%Y-%m)

With a script

#!/bin/bash
ddd=$(date -d "-1 month" +%Y-%m)
xmessage -timeout 10 $ddd

and the cronjob line

* * * * * DISPLAY=:0 /path/to/script.sh

it works very well on my system – see How to start a GUI application from cron? and the Cron HowTo.

dessert
  • 40,956