I am trying to set up a script that runs 2 mate-terminal instances, each with a different command.
The script is set up as a cronjob.
The problem is, while the script works fine when executed manually, in terminal, it fails to open the 2 terminal windows.
I tried different approaches, but nothing worked. I also have gnome-terminal installed, same result.
The script runs, kills the processes and their terminal but that's it.
LE: The script runs, it kills all the processes and terminal windows but it does not open the new terminal windows with the given commands.
This is an old application and the only logging is visible in the terminal, in real time. Since there is no plan for upgrading the application anytime soon, to export the log to an external file, this is the requirement.
Any ideas on what I am doing wrong?
#!/bin/bash export DISPLAY=:10.0 export XAUTHORITY=/home/lxadmin/.Xauthority export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin echo "Script started at $(date)" >> /home/lxadmin/Logs/MyApp.log close_running_terminals() { echo "Closing running terminals" >> /home/lxadmin/Logs/MyApp.log pkill -f "node" pkill -f "npm" for terminal in $(pgrep -f mate-terminal); do if ps -o args= -p $terminal | grep -qE 'node|npm'; then echo "Killing mate-terminal process: $terminal" >> /home/lxadmin/Logs/MyApp.log kill -9 $terminal fi done sleep 2 } open_terminal_and_run() { local cmd=$1 echo "Running command: $cmd" >> /home/lxadmin/Logs/MyApp.log /usr/bin/mate-terminal -- /bin/sh -c "$cmd; exec bash" #/usr/bin/mate-terminal -- bash -c "$cmd; exec bash" } close_running_terminals open_terminal_and_run "cd /home/lxadmin/Servers/MyApp/server && /usr/local/lib/nodejs/node-v12.13.1-linux-x64/bin/nodemon app.js" sleep 5 open_terminal_and_run "cd /home/lxadmin/Servers/MyApp/client && /usr/local/bin/npm run dev" echo "Script completed at $(date)" >> /home/lxadmin/Logs/MyApp.log