Automate file start
Automate file start
Hello,
On CentoS 7 I sometimes have to launch 2 files. To do this, I run the following 4 commands:
cd /home/gms_test
./GameManagerServer&
cd /home/zs_test
./ZoneServer&
I want to know if I can automate this every 15 minutes.
Thanks in advance
On CentoS 7 I sometimes have to launch 2 files. To do this, I run the following 4 commands:
cd /home/gms_test
./GameManagerServer&
cd /home/zs_test
./ZoneServer&
I want to know if I can automate this every 15 minutes.
Thanks in advance
Re: Automate file start
Learn how to write a systemd unit file and have it launch it for you. It will also restart it when it fails (if you tell it to).
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Re: Automate file start
Re: Automate file start
A note:
is same as
unless the programs expect the current working directory to be same as file location.
You can store the commands in a script file:
If you give the file executable attribute chmod +x example.sh, then you can run it:
You can also give the script to cron or systemd. With systemd you would have example.service unit that runs the script and example.timer unit that starts the service unit ever 15 minutes.
Are you sure that you have to run these ever 15 minutes?
Code: Select all
cd /home/gms_test
./GameManagerServer&
cd /home/zs_test
./ZoneServer&
Code: Select all
/home/gms_test/GameManagerServer &
/home/zs_test/ZoneServer &
You can store the commands in a script file:
Code: Select all
$ cat example.sh
#!/bin/bash
/home/gms_test/GameManagerServer
/home/zs_test/ZoneServer
Code: Select all
./example.sh &
Are you sure that you have to run these ever 15 minutes?
Re: Automate file start
Using cron is a very poor second to setting up systemd to do this for you.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke
Re: Automate file start
jlehtone wrote: ↑2022/08/07 12:03:49A note:is same asCode: Select all
cd /home/gms_test ./GameManagerServer& cd /home/zs_test ./ZoneServer&
unless the programs expect the current working directory to be same as file location.Code: Select all
/home/gms_test/GameManagerServer & /home/zs_test/ZoneServer &
You can store the commands in a script file:If you give the file executable attribute chmod +x example.sh, then you can run it:Code: Select all
$ cat example.sh #!/bin/bash /home/gms_test/GameManagerServer /home/zs_test/ZoneServer
You can also give the script to cron or systemd. With systemd you would have example.service unit that runs the script and example.timer unit that starts the service unit ever 15 minutes.Code: Select all
./example.sh &
Are you sure that you have to run these ever 15 minutes?
Hello,
With crontab -e I add that:
The chmod 754 script:
There is again an error ?
Re: Automate file start
The cat example.sh was merely a command to show the content of file example.sh.
The content was just:
Wait, you do have the script file in directory /root/scripts and you do show that directory in GUI
That means that these programs are run with root privileges and you have GUI session as root.
Both are very bad practice.
The content was just:
Code: Select all
#!/bin/bash
/home/gms_test/GameManagerServer
/home/zs_test/ZoneServer
Wait, you do have the script file in directory /root/scripts and you do show that directory in GUI
That means that these programs are run with root privileges and you have GUI session as root.
Both are very bad practice.
Re: Automate file start
I deleted cat example.sh but it still does not work.
This may be related to the missing dot, which I usually use to launch the file manually via SSH.
However, I don't really know where to put the point.
This may be related to the missing dot, which I usually use to launch the file manually via SSH.
However, I don't really know where to put the point.
Re: Automate file start
The "dot" means "current working directory". When you do
cd /home/gms_test
you set the current working directory to be /home/gms_test
In that situation ./ means /home/gms_test/
When you run a command, it inherits the current working directory (cwd) of the environment
As I said in my first comment, if the program does assume that its file is in cwd, i.e. it tries
to read other files relative to cwd, then it will not find those files.
cd /home/gms_test
you set the current working directory to be /home/gms_test
In that situation ./ means /home/gms_test/
When you run a command, it inherits the current working directory (cwd) of the environment
Code: Select all
cd /tmp
/home/gms_test/GameManagerServer ( cwd==/tmp )
cd /home/gms_test
/home/gms_test/GameManagerServer ( cwd==/home/gms_test )
./GameManagerServer ( cwd==/home/gms_test )
to read other files relative to cwd, then it will not find those files.