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:
echo $DISPLAY
The output will be something like this:
:0
or
:1
Let's assume your DISPLAY
variable is :1
, then add to your script before command with GUI application DISPLAY=:1
variable, i.e.:
#!/bin/bash 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:
/etc/rc.d/rc.local
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. /path/to/script.sh 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