Linux Basic 6:vim and some shell scripts

Source: Internet
Author: User

Content of this week's job:

1. Copy the/etc/rc.d/rc.sysinit file to the/tmp directory and add # to the beginning of the line with at least one whitespace character in the/tmp/rc.sysinit file;

2, copy/boot/grub/grub.conf to/tmp directory, delete the blank character of the beginning of the/tmp/grub.conf file;

3. Remove the # and white space characters from the/tmp/rc.sysinit file that begin with # and followed by at least one white-space character

4. Add # to the beginning of the first three lines in the/tmp/grub.conf file;

5. Change the last 0 of all enabled=0 or gpgcheck=0 in the/etc/yum.repos.d/centos-media.repo file to 1;

6, every 4 hours to perform a backup of the/etc directory, back up to the/backup directory, save the directory named Shape etc-201608300202

7, weekly 2,4,6 backup/var/log/messages file to/backup/messages_logs/directory, save the file name like messages- 20160830

8, every two hours every day to take the current system/proc/meminfo file in the beginning of all the information in the S./stats/memory.txt file

9, working days of work time, every two hours to perform the echo "Howdy"

Script Programming Exercises

10, create the directory/tmp/testdir-the current date and time;

# tt= ' Date ' +%y-%m-%d_%h:%m ' && mkdir "/tmp/testdir-$tt" && ls-d!$/tmp/testdir-2016-09-02_19:38:29

11. Create 100 empty files in this directory: file1-file100

# vim/tmp/test11.sh
#!/bin/bash#for N in {1..100};d o [-D "/tmp/file$n"] &>/dev/null | | mkdir "/tmp/file$n" done
# bash /tmp/test11.sh# ls -d /tmp/file*/tmp/file1    /tmp/file18   /tmp/file27  /tmp/file36  /tmp/file45  /tmp/file54                                           /tmp/file63  /tmp/file72  /tmp/file81  /tmp/file90/tmp/file10    /tmp/file19  /tmp/file28  /tmp/file37  /tmp/file46  /tmp/file55                                           /tmp/file64  /tmp/file73  /tmp/file82  /tmp/file91/tmp/ File100  /tmP/file2   /tmp/file29  /tmp/file38  /tmp/file47  /tmp/file56                                            /tmp/file65  /tmp/file74  /tmp/file83  /tmp/file92 /tmp/file11   /tmp/file20  /tmp/file3   /tmp/file39  /tmp/ file48  /tmp/file57                                         /tmp/file66  /tmp/file75  /tmp/file84   /tmp/file93/tmp/file12   /tmp/file21  /tmp/file30  /tmp/file4    /tmp/file49  /tmp/file58                                          /tmp/file67  /tmp/file76  /tmp/file85   /tmp/file94/tmp/file13   /tmp/file22  /tmp/file31  /tmp/file40   /tmp/file5   /tmp/file59                                          /tmp/file68  /tmp/file77   /tmp/file86  /tmp/file95/tmp/file14   /tmp/file23  /tmp/file32   /tmp/file41  /tmp/file50  /tmp/file6                                         /tmp/file69  /tmp/file78  /tmp/ file87  /tmp/file96/tmp/file15   /tmp/file24  /tmp/file33  /tmp/ file42  /tmp/file51  /tmp/file60                                         /tmp/file7   /tmp/ file79  /tmp/file88  /tmp/file97/tmp/file16   /tmp/file25  /tmp/ file34  /tmp/file43  /tmp/file52  /tmp/file61                                         /tmp/file70  /tmp/file8   / tmp/file89  /tmp/file98/tmp/file17   /tmp/file26  /tmp/file35  / tmp/file44  /tmp/file53  /tmp/file62                                         /tmp/file71  /tmp/file80   /tmp/file9   /tmp/file99

12. Display the user name of the user who is located in the/ETC/PASSW D file in the first even row;

# vim/tmp/test12.sh
#!/bin/bash#




13. Create 10 user user10-user19, password and user name;

# vim/tmp/test13.sh
#!/bin/bash#for x in {10..19};d o if! ID user$x &>/dev/null;then useradd user$x fi echo "user$x" | passwd--stdin user$x &>/dev/nulldone
# bash /tmp/test13.sh# grep  "^user1[0-9]"  /etc/passwduser1:x:3016:3018::/home/user1:/ bin/bashuser90:x:3017:3030::/home/user90:/bin/bashuser98:x:3018:3031::/home/user98:/bin/bashuser10:x:3019:3020 ::/home/user10:/bin/bashuser11:x:3020:3021::/home/user11:/bin/bashuser12:x:3021:3022::/home/user12:/bin/ bashuser13:x:3022:3032::/home/user13:/bin/bashuser14:x:3023:3023::/home/user14:/bin/bashuser15:x:3024:3024::/ home/user15:/bin/bashuser16:x:3025:3025::/home/user16:/bin/bashuser17:x:3026:3026::/home/user17:/bin/ bashuser18:x:3027:3027::/home/user18:/bin/bashuser19:x:3028:3028::/home/user19:/bin/bash# grep  "^ USER1[0-9] " /etc/shadow |cut -d: -f1,2user10:$6$ptzjnxme$k8/ wldibuhlxdmmzv89fwcnxcb3lpgbdqnyez19xreo3mwvacxveucsojbsezoqpbkth1wuzq39yy$user11:$6$t/geqh.l$ 4g2mczv22cwfvd03z7rv7g8dmk/u8dkodau5xmovywdmgfypo3zn8xhzjjcae0oxdcayi/9ekikgf$user12:$6$apvohbyv$ 7qwyd7r.kj4zrynuejclfzrecksdeiwvp1paqzdbkomdpqiwot2u1mrq8kpyin4xdvdtpjiz/efyl$user13:$6$kv8upaa9$dgvk5hhp4xvr.npvti1mamzyrvoewxxef1hlastqnshq9x3jurbjtglltbocjy2zxa43xxgpwebwc$user14:$6$1r4cy8be$ mkfsf3afbhih2w4jgzjt5iio2ge2y00fv5/oekx/6qwo/p95fhkp70rxriqil9/bkcsi1gh7yoocx$user15:$6$b0ustd5w$ br4ejvrplimx.emv4y8ih.vg.uf9.t4tznaiqjyohsqjvsafpz/ygncon4qxk8u2wp/rhelnlh8j5$user16:$6$wf3odfsz$rk6.dr79p/ WCPWQ45K1C.M5WJRSOSRCYTL50EH.1UCXL. Joir/zvwy5bkyev6iujonhw7lw0oh34$user17:$6$qmszh8wr$qltnqak/viiytlz6ogdhfgdyzvkzchgcvifwt8w6ilncnchwgqeo8g/lj. p462yfgcvnu2oxcbxjy$user18:$6$qgjpui4i$ 1qrvemxebo3olxwgwuwsnuump0s0ivgddwwsxwudi9lvngvyd6vkxa9051qxyue0carcutsnhbvsp$user19:$6$ehlb9bfu$ bpoupp8ghcsp.i8nlhsqepztxtge2p/s9fgpepls6g9myvjbjhpdwhccpjtvr63iqkzo10l5lyepi$

14, create 10 empty files file10-file19 in/tmp/;

# vim/tmp/test14.sh
#!/bin/bash#for CreateFile in {10..19};d o if [!-e "/tmp/file$createfile"];then Touch "/tmp/file$createfile" Fidonels-l/tmp/file1[0-9]
# bash /tmp/test14.sh-rw-r--r--.  1 root root 0 9 Month    2  16:58 /tmp/file10-rw-r--r--.  1 root root 0 9 Month    2 16:58  /tmp/file11-rw-r--r--.  1 root root 0 9 Month    2 16:58 /tmp /file12-rw-r--r--.  1 root root 0 9 Month    2 16:58 /tmp/ File13-rw-r--r--.  1 root root 0 9 Month    2 16:58 /tmp/ File14-rw-r--r--.  1 root root 0 9 Month    2 16:58 /tmp/ File15-rw-r--r--.  1 root root 0 9 Month    2 16:58 /tmp/ File16-rw-r--r--.  1 root root 0 9 Month    2 16:58 /tmp/ File17-rw-r--r--.  1 root root 0 9 Month    2 16:58 /tmp/ File18-rw-r--r--.  1 root root 0 9 Month   &nbsP;2 16:58 /tmp/file19 

15. Change the file10 and the genus to user10, and so on.

# vim/tmp/test15.sh
#!/bin/bash#for i in {10..19};d o if! grep "^user$i"/etc/group >&/dev/null;then groupadd "user$i" fi if! ID "user$i" &>/dev/null;then useradd-g user$i user$i fi chown user$i:user$i "/tmp/file$i" done
[[email protected] ~]# bash /tmp/test15.sh | ls -l /tmp/file1[0-9]- Rw-r--r--.  1 user10 user10 0 9 Month    2 16:58 /tmp/ File10-rw-r--r--.  1 user11 user11 0 9 Month    2 16:58 /tmp/ File11-rw-r--r--.  1 user12 user12 0 9 Month    2 16:58 /tmp/ File12-rw-r--r--.  1 user13 user13 0 9 Month    2 16:58 /tmp/ File13-rw-r--r--.  1 user14 user14 0 9 Month    2 16:58 /tmp/ File14-rw-r--r--.  1 user15 user15 0 9 Month    2 16:58 /tmp/ File15-rw-r--r--.  1 user16 user16 0 9 Month    2 16:58 /tmp/ File16-rw-r--r--.  1 user17 user17 0 9 Month    2 16:58 /tmp/ File17-rw-r--r--.  1 user18 user18 0 9 Month     2 16:58 /tmp/file18-rw-r--r--.  1 user19 user19 0 9 Month     2 16:58 /tmp/file19


Linux Basic 6:vim and some shell scripts

Related Article

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.