Can you write these scripts? Rh033-level simple script

Source: Internet
Author: User

Write a script:
1. Create a directory/tmp/scripts
2. Switch the working directory to this directory.
3. Copy the/etc/PAM. d directory to the current directory and run the test command again.
4. Change the owner of test and its files and subdirectories to RedHat.
5. Change the permissions of other users of files in the test and its subdirectories to No permissions.

Write a script:
1. display the current system date and time, and then create the directory/tmp/lstest
2. Switch the working directory to/tmp/lstest.
3. create directories a1d, b56e, and 6 Test
4. Create an empty file XY, x2y, 732
5. list files or directories starting with a, X, or 6 in the current directory;
6. list files or directories starting with letters, followed by any number, and followed by any characters in length under the current directory;

Write a script to complete the following functions:
1. pass two integers to the script to calculate and display the sum, difference, product, and operator of the two integers respectively.

Write a script:
1. Switch the working directory to/var
2. Send hello to each file or subdirectory in the/var directory in sequence, for example:
(Tip: For file in/var/*; or for file in 'ls/var ';)
Hello, log
Hello, run
3. There are multiple files in the statistics/var directory and the files are displayed.

Write a script:
1. Set the value of the variable file to/etc/passwd.
2. read lines 2, 4, 6, 10, 13, and 15 of the file/etc/passwd cyclically and display the content. (Note: line = 'head-2/etc/passwd | tail-1' can get 2nd rows)
3. Save these rows to the/tmp/mypasswd file.

Write a script:
1. Set the value of the variable file to/etc/passwd.
2. Send hello to each user in/etc/passwd in sequence, for example, (note: lines = 'wc-L/etc/passwd | cut-d ""-f1 ')
Hello, Root.
3. Count the total number of users

Write a script:
1. Set the value of the variable file to/etc/passwd.
2. Send hello to each user in/etc/passwd in sequence and specify the ID of the other user, as shown in the following figure: lines = 'wc-L/etc/passwd | cut-d ""-f1 ')
Hello, root, your uid is 0.
3. Count the total number of users

Write a script:
1. Add 10 users from user1 to user10, but the user must not be added;

Write a script:
1. Run the ping command to test whether all hosts between 192.168.0.151 and 192.168.0.254 are online,
If it is online, "IP is up." is displayed ."
If it is not online, "IP is down." is displayed ."

Write a script:
1. Change the first and last letters of all files in the/var/directory to uppercase;

Write a script:
1. Save the rows starting with not # (well number) in the/etc/sysctl. conf file to/tmp/sysctl. conf.
2. If the value of net. ipv4.ip _ forward in the/tmp/sysctl. conf file is 0, change the value to 1.
3. display the command names before the equal signs one by one in order, and add their numbers to each command name, as shown in the following figure:
1 Net. ipv4.ip _ forward
2 kernel. sysrq
4. Add comments to each line in the/tmp/sysctl. conf file. That is, add a line starting with # Before each non-blank line and save it to the file. The content is shown as follows:
# A parameter.

Write a script:
1. Assume that an object contains the following lines:
/Etc/inittab
/Etc/PAM. d/sudo
/Usr/share/doc
/Usr/local/
/Etc/sysconfig/
/Var/log/messages
2. Retrieve the file name that does not contain the path in each row of the above file. For example, the file name of/etc/inittab is inittab, and the file name of/etc/sysconfig/is sysconfig;
3. Change the second letter of each file name to uppercase;

1. Write a script:
Determine whether a file exists. If yes, the file exists;

2. Write a script:
Determine whether a file exists. If yes, the file exists; otherwise, the file does not exist;

3. Write a script:
1) Let the user pass a path through the command line;
2) judgment:
If it is a common file, it is displayed;
Otherwise, a directory is displayed;
Otherwise, the link is displayed;
Otherwise, the display cannot be identified.

4. Calculate the sum of all even numbers within 100;

5. Write a script:
Determine whether the user input is Q or Q. If yes, "quting..." is displayed. Otherwise, "Are you crazy?" is displayed ?";

Write a script:
1. Determine whether a specified script is a syntax error. If an error occurs, the user is reminded to press Q or Q to ignore the error and exit. Other keys can be opened through vim;
2. If an error persists after you open and edit the file through vim, repeat the content in step 1. Otherwise, exit is disabled normally.

Write a script:
1. Ask the user to enter a user name on the keyboard to determine whether the user exists. If the user exists, the default shell of the user is returned. If the user does not exist, the system prompts that the user does not exist.
2. Do not exit the script after the judgment is complete, but continue to prompt n | n (next) Users enter other user names to make the next judgment, and enter any other characters to exit;

Write a script:
1. Add 20 users to the system, the name is linuxer1-linuxer20, the password is their username, to use the while loop;
2. Requirement: Determine whether a user exists before adding a user. If the user already exists, the user will not be added;
3, after adding, display each user name of the linuxer1-linuxer20 and the corresponding uid number and GID number, such
Stu1, uid: 1000, Gid: 1000 (awk is required in this step)

Write a script:
1. Scan the online status of hosts in the 192.168.0 network segment, but you need to prompt the user to enter an IP address range by specifying the starting IP address and ending IP address. The displayed result is as follows:
The host 192.168.0.1 is up.
The host 192.168.0.2 is down.
2. implement with a while loop;
3. The output result of the host's online status must be displayed on the screen, and all host information must be saved to/tmp/host_state;
4. Add a # (well number) to the first row of all rows in the/tmp/host_state file whose host status is down );
5. display the total number of online and offline hosts in the specified range respectively;

Write a script:
Displays the names, numbers, and vsz values of all processes whose vsz segments are greater than 4000 on the current system;

Write a script:
Check whether the RedHat user has logged on to the system. If yes, notify the current script executor "RedHat is logged on .";
Otherwise, test again after five seconds of sleep until the user logs on to the system and exits;
Requirement: Use the until Loop

Write a script:
1. prompt the user to select the network card to be set;
2. the user is prompted to use DHCP or static as the bootproto of the selected Nic.
A. if you select DHCP, set the value of bootproto in the configuration file to DHCP, and then restart the NIC;
B. if you select static, set the value of bootproto in the configuration file to static, and prompt the user to enter the IP address, subnet mask, and gateway. The Gateway can be empty, however, the IP address or subnet mask cannot be blank. Restart the NIC after the settings are complete;
3. Regardless of the above dynamic or static settings, after the configuration is complete, the information of the nic ip address is displayed to the user again;

Considerations: 1. If you do not want to set any changes, how can you exit?
2. if the user has already set some information, such as the IP address, but does not want to set it, and uses Ctrl + C, how can this problem be solved?

Write a script:
1. Scan the online status of hosts in the 192.168.0 network segment, but you need to prompt the user to enter an IP address range by specifying the starting IP address and ending IP address. The displayed result is as follows:
The host 192.168.0.1 is up.
The host 192.168.0.2 is down.
Note: function implementation is required;
2. implement with a while loop;
3. The output result of the host's online status must be displayed on the screen, and all host information must be saved to/tmp/host_state;
4. Add a # (well number) to the first row of all rows in the/tmp/host_state file whose host status is down );
5. display the total number of online and offline hosts in the specified range respectively;

Write a script:
1. prompt the user to enter a user name;
2. Implement using functions:
Determine whether a user exists and pass the user name through parameters;
If the user exists, the user's shell and uid are displayed.
If the user does not exist, the user does not exist;

Write a script:
1. the user is prompted to enter "mem" to view the physical memory usage information of the local machine, and "Swap" to display the virtual memory usage information;
2. When the user inputs MEM, the user obtains the physical memory size, used space, and free space of the current host. If the used space exceeds 90% of the total space, the user is warned in red; otherwise, the percentage of remaining space is displayed in green;
3. When you enter "Swap", obtain the virtual memory size, used space, and idle space of the current host. If the used space exceeds 90% of the total space, the warning is in red. Otherwise, the percentage of remaining space is displayed in green;
4. Other information indicates an incorrect input;

Write a script:
1. Use a function to obtain the physical memory size, used space, and free space of the current host. If the used space exceeds 90% of the total space, the system will warn you in red. Otherwise, the percentage of remaining space is displayed in green;
2. Use a function to obtain the virtual memory size, used space, and idle space of the current host. If the used space exceeds 90% of the total space, the system will warn you in red; otherwise, the percentage of remaining space is displayed in green;
3. A prompt is displayed, indicating that the input mem displays the usage of the physical memory space. The input swap displays the usage of the virtual memory space; any other characters prompt the user to use the script and exit the script;

Write a script:
1. Define a function
1) the mem or swap parameter is acceptable;
2) When the mem parameter is accepted, the size of the physical memory of the current host, used space, and idle space are obtained. If the used space exceeds 90% of the total space, a red warning is given; otherwise, the percentage of remaining space is displayed in green;
3) when SWAp is accepted, obtain the virtual memory size, used space, and idle space of the current host. If the used space exceeds 90% of the total space, a red warning is given; otherwise, the percentage of remaining space is displayed in green;
3. A prompt is displayed in the main program, indicating that the input mem can display the usage of the physical memory space; the input swap can display the usage of the virtual memory space; any other characters prompt the user to use the script and exit the script;

Write a script
1. If the/tmp/NET directory exists, switch to this directory. Otherwise, create this directory first and switch to it;
2. Download ftp: // 192.168.0.254/pub/files/rh033.txt to this directory, and set the name to add the current date and time after the original name, as shown in the following figure:
Rh033-2011-04-25-09-31-10.txt
3. Report the download to the user after the download is completed.

Write a script:
1. Create a function and accept two parameters:
1) The first parameter is the URL to download the file, and the second parameter is the directory, that is, the location saved after the download;
2) If the directory provided by the user does not exist, the system prompts whether to create the directory. If the directory is created, the system continues to execute. Otherwise, the function returns an error value of 51 to the calling script;
3) if a directory exists, download the file. After the download command is executed, test whether the file is successfully downloaded. If yes, return 0 to the script. Otherwise, return 52 to the call script;
2. Main function:
1) prompt the user to enter the URL of the file to be downloaded and the directory to be saved;
2) Call the function to execute the download. If the function returns 0, the download is successful. If the function returns 51, the download fails because the specified directory does not exist. If the function returns 52, indicates that the download process fails;

 

Baidu's two shell programming questions:
1. write scripts. You can use shell and Perl. Find 100 files starting with ABC in the/tmp directory, and save the first line of these files to file new.
2. write scripts and use shell and Perl. Save all rows in file B but not in file a as file C and count the number of lines in file C.

Shell script interview questions for a company

The content of a text file is as follows:
User1 ABCD
User2 g23d
User3 vgq2
...... ......

Create users in batches Based on the file content. The first column is the user name and the second column is the password of the corresponding user;

 

Write a script:
1. download the file ftp: // 192.168.0.254/pub/files/access_log to the/tmp directory;
2. Analyze and display the top five IP addresses at the beginning of the line in the/tmp/access_log file that appear the most frequently, and describe how many times each IP address appears;
3, take out the/tmp/access_log file with http: //, followed by a domain name or IP address string, such as: http://www.linux.com/install/images/style.css of the http://www.linux.com of this string; the first five most frequently displayed items are displayed;
Requirements: 2nd and 3 functions are implemented in the form of functions;

O & M engineer interview questions:
Write a shell script to obtain the network address of the local machine. For example, if the local IP address is 192.168.100.2/255.255.255.0, its network address is 192.168.100.1/255.255.255.0.

Kaspersky interview questions:
The content of a file is as follows:
Jack huaxue 90
Tom huaxue 70
Jack shuxue 99
Tom shuxue 80

Calculate the average score of the two subjects of Jack and Tom, and use shell

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.