How to execute shell script via crontab?
- Slaxmax
- Contributor
- Posts: 408
- Joined: 03 Jan 2013, 09:51
- Distribution: KDE4
- Location: Campinas Brazil https://goo.gl/yrxwKi
How to execute shell script via crontab?
I tried a few methods suggested in google, but none of them worked.
“DNA is like a computer program but far, far more advanced than any software ever created.”
― Bill Gates, The Road Ahead
― Bill Gates, The Road Ahead
- brokenman
- Site Admin
- Posts: 6105
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
Re: How to execute shell script via crontab?
I just tested this which works.
As guest create a script at /home/guest/testjob like so:
Make it executable.
As root run:
Press insert
Add your conjob
28 18 30 08 * /home/guest/testjob
Press Esc
Type: :wq
Press Enter
Wait until the job runs at: 18:28 on August 30th and check /tmp/out
In this line the meanings are:
28 – 28th Minute
18 – 06 PM
30 – 30th Day
08 – 8th Month (August)
* – Every day of the week
As guest create a script at /home/guest/testjob like so:
Code: Select all
echo "echo cronjob ran at \`date +%s\` > /tmp/out" > /home/guest/testscript
As root run:
Code: Select all
crontab -e -u guest
Add your conjob
28 18 30 08 * /home/guest/testjob
Press Esc
Type: :wq
Press Enter
Wait until the job runs at: 18:28 on August 30th and check /tmp/out
In this line the meanings are:
28 – 28th Minute
18 – 06 PM
30 – 30th Day
08 – 8th Month (August)
* – Every day of the week
How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.
- Slaxmax
- Contributor
- Posts: 408
- Joined: 03 Jan 2013, 09:51
- Distribution: KDE4
- Location: Campinas Brazil https://goo.gl/yrxwKi
Re: How to execute shell script via crontab?
Thanks
Your script works, but this no...
or other "more complex" script.
this script write test$$, but no execute notify-send
Why?
Your script works, but this no...
Code: Select all
#!/bin/bash
/usr/bin/notify-send "hi welcome" && echo "blabla" > /home/guest/test$$
this script write test$$, but no execute notify-send
Why?
“DNA is like a computer program but far, far more advanced than any software ever created.”
― Bill Gates, The Road Ahead
― Bill Gates, The Road Ahead
- brokenman
- Site Admin
- Posts: 6105
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
Re: How to execute shell script via crontab?
In this case cron probably doesn't have access to the DBUS_SESSION_BUS_ADDRESS environment variable (as root). Also you may need to run notify-send as: sudo -u guest notify-send
How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.
- Slaxmax
- Contributor
- Posts: 408
- Joined: 03 Jan 2013, 09:51
- Distribution: KDE4
- Location: Campinas Brazil https://goo.gl/yrxwKi
Re: How to execute shell script via crontab?
Does not work for root too.
“DNA is like a computer program but far, far more advanced than any software ever created.”
― Bill Gates, The Road Ahead
― Bill Gates, The Road Ahead
- brokenman
- Site Admin
- Posts: 6105
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
Re: How to execute shell script via crontab?
This worked for me:
also
Code: Select all
guest@porteus:~$ crontab -l
23 23 30 08 * export DISPLAY=:0.0 && /usr/bin/notify-send "Your cronjob called notify-send directly"
Code: Select all
guest@porteus:~$ crontab -l
26 23 30 08 * export DISPLAY=:0.0 && /home/guest/testcron
guest@porteus:~$ cat /home/guest/testcron
/usr/bin/notify-send "Your cronjob has run from a script"
How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.
- Slaxmax
- Contributor
- Posts: 408
- Joined: 03 Jan 2013, 09:51
- Distribution: KDE4
- Location: Campinas Brazil https://goo.gl/yrxwKi
Re: How to execute shell script via crontab?

Thanks!
“DNA is like a computer program but far, far more advanced than any software ever created.”
― Bill Gates, The Road Ahead
― Bill Gates, The Road Ahead
- francois
- Contributor
- Posts: 6501
- Joined: 28 Dec 2010, 14:25
- Distribution: xfce plank porteus nemesis
- Location: Le printemps, le printemps, le printemps... ... l'hiver s'essoufle.
Re: How to execute shell script via crontab?
Slaxmax:
I think that smilies of yours should be added to the smilies table of the forum. I wonder if one of the dev could do that.
I think that smilies of yours should be added to the smilies table of the forum. I wonder if one of the dev could do that.

Prendre son temps, profiter de celui qui passe.
- Slaxmax
- Contributor
- Posts: 408
- Joined: 03 Jan 2013, 09:51
- Distribution: KDE4
- Location: Campinas Brazil https://goo.gl/yrxwKi
Re: How to execute shell script via crontab?
I agree. Very cool.francois wrote:Slaxmax:
I think that smilies of yours should be added to the smilies table of the forum. I wonder if one of the dev could do that.
“DNA is like a computer program but far, far more advanced than any software ever created.”
― Bill Gates, The Road Ahead
― Bill Gates, The Road Ahead