Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Application of shell script (1) case

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Case one

Write a login welcome script for root users that reports the number of processes in the current host, the number of logged-in users, and the disk utilization of the root file system.

1. Create a new script file, welcome.sh, in the / root directory with the vim command, as follows:

Note:'{print $5}'is in single quotation marks, not reverse apostrophes.

two。 Use the chmod command to add execute (x) permissions to the welcome.sh file

3. Modify the / root/.bash_profile file to call the welcome.sh script every time a root user logs in to the system

4. Authentication: log back in using the root user to verify the output of the welcome script

Case two

Write three script programs, start, stop and status, to start and stop various system services.

1. Create a new script file start.sh in the / bin directory with the vim command

two。 Set x permissions

3. Modify alias

Alias start='start.sh' / / if you want to type start for direct execution, you need to create a new alias (this alias is temporary and will expire after the system restart. If it is in force permanently, you need to modify the / root/.bashrc configuration file to add this command.)

4. Test script

The script files stop and status are similar to start and are not described here.

Case three

Filter out the MAC address of the local eth0 Nic and assign it to the variable HWaddr.

Case four

Write a small script sumsquare.sh, which is used to calculate the sum of squares of two integers.

1. Create script

two。 Give the script execution permission

3. test

Case five

Write a small script, memusage.sh, to settle the memory usage according to the results of the Free command.

1. Create script

Note: in linux systems, it is recommended that the actual memory usage be based on the used Buffers/Cache and calculate the ratio to the total memory space. In addition, because Bash Shell does not support decimal operations and the percentage of usage is less than 1, you need to multiply the molecule by 100 before calculating the result.

two。 Give the script x permissions

3. Test script

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report