1. Simple script
1. Create a script
(1) #Switch to the directory where you will save the script
cd /root/bigdata/install/
(2) Write the script autorun.sh
The following is the script content:
(The execution script means to create an input.txt folder in the /home directory and write the current date and hostname)
#!/bin/bash
date >> /home/input.txt
hostname >> /home/input.txt
2. Add the script to the startup file
Execute the following command:
cd /etc/rc.d
vi rc.local
Add the script you wrote in the last line (write from the root directory)
/root/bigdata/install/autorun.sh
3. Grant permissions
chmod +x /etc/Your rc.local file address needs to add the file name Example: (/etc/rc.d/rc.local)
chmod +x You need to add the file name to the address where the sh file is stored Example: (/root/bigdata/install/autorun.sh)
4. Restart Linux
sudo reboot
5. Check the effect
cat input.txt
2. Start the jar package script
1. Write the jar package startup script
#!/bin/sh
export JAVA_HOME=/bigdata/install/jdk-1.8.0/
export PATH=$JAVA_HOME/bin:$PATH
cd /root/bigdata/install
echo "开机启动">log.log
nohup java -jar demo01-0.0.1-SNAPSHOT.jar >>log.log 2>&1 &
Other steps are the same as above