Script 1: Write a login welcome script for root users:
1, with vi command in the/root directory is a new script file welcome.sh, the contents are as follows:
2, using the chmod command to welcome.sh file to increase the execution (x) permissions
3. Modify the/root/.bash_profile file to invoke the welcome.sh script every time the root user logs on to the system
#vi/root/.bash_profile Add the following:
4. Verify: Login with root user to verify the output information of the Welcome script
Script 2: Scripting to start, stop, and display system service status:
1, with vi command in the/root/bin directory is a new script file status to view the status of the Crond service, which reads as follows:
Set X Permissions
Script files stop and start are similar to status and can be modified slightly.
Script 3: Write a health monitoring script/opt/monitor.sh that records CPU load, memory and swap space, disk space, recent user logon, and time information.
1, with vi command in the/OPT directory is a new script file monitor.sh, the contents are as follows:
#!/bin/bash
Mkdir-p/var/log/runrec
Recfile= "/var/log/runrec/running.today"
Rectime= ' date + '%y-%m-%d%h:%m '
Loadrec= ' uptime '
Memrec= ' Free-m '
Diskrec= ' Df-ht '
lastloginrec= ' Last-n 20 '
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Record time: $RecTime
CPU Load Information: $LOADREC
Memory Information: $MemRec
Disk Usage Information: $DiskRec
Last Login to users record: $LastLoginRec ">> $RecFile
2, using the chmod command to monitor.sh file to increase the execution (x) permissions
3. Whether the test script can run correctly and output the correct information
4, set the planning task, request every 15 minutes to hold a monitor.sh script, and confirm Crond service has started.
To create a scheduled task:
#crontab –e contents are as follows
*/15 * * * */opt/monitor.sh
View the Crond service status and set the Crond to boot automatically.
#service Crondstatus
#chkconfig--level Crond on
Script 1: Writing a shell script monitoring host
1, with vi command in the/root directory is a new script file sysmon.sh, the contents are as follows: