On Centos6 I have this script and i need to execute it once after reboot in terminal.
How can i do this?
If I execute like sh /path/to/script.sh - all good, but if I add in rc.local (sh /path/to/script.sh) or crontab (@reboot sh /path/to/script.sh)- nothing happens.
I will be glad to any help.

gnome-terminal -x sh -c 'zenity --info --text="Msg1" --title="Text1..." --timeout=10
zenity --info --text="Msg2" --title="Text2..."  --timeout=10
zenity --info --text="Msg3" --title="Reboot..."  --timeout=10
sleep 1
exec bash'
  • /usr/share/gnome/autostart/script.desktop - doesn't work too... – Oleg Kalinin Jul 24 '18 at 7:00

Gnome Terminal is X application (GUI application). If you want to run any X application from cron, just "let him know" which display you're using since cron doesn't execute commands within your normal shell environment.

First of all detect which display is being used in your system:


The output will be something like this:




Let's assume your DISPLAY variable is :1, then add to your script before command with GUI application DISPLAY=:1 variable, i.e.:

DISPLAY=:1 gnome-terminal -x sh -c 'zenity --info --text="Msg1" --title="Text1..."  --timeout=10;<some_command>;zenity --info --text="Msg2" --title="Text2..."  --timeout=10;<some_command>;zenity --info --text="Msg3" --title="Reboot..."  --timeout=10;sleep 1; exec bash'

Besides cron there is another possibility in CentOS to run a something once at system startup - rc-local service mechanism. Create (if it isn't created yet) file:


with the content:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.


exit 0

Put to the file all of the commands you wish to execute at startup.

Make the rc.local file executable:

chmod +x /etc/rc.d/rc.local

Enable rc-local service and start it:

systemctl enable rc-local
systemctl start rc-local

Check if the service is running properly:

systemctl status rc-local
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.