设为首页 收藏本站
查看: 1230|回复: 0

[经验分享] Linux作业(3)

[复制链接]

尚未签到

发表于 2018-5-18 11:56:48 | 显示全部楼层 |阅读模式
1、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
  [root@localhost~]# ls /etc/rc.d/init.d/
functions  netconsole  network README
[root@localhost ~]# grep -o "\<.*\>()"/etc/rc.d/init.d/functions
checkpid()
__pids_var_run()
__pids_pidof()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
echo_success()
echo_failure()
echo_passed()
echo_warning()
update_boot_stage()
success()
failure()
passed()
warning()
action()
strstr()
2、使用echo命令输出一个绝对路径,使用grep取出其基名;
  [root@localhost~]#  echo "/etc/rc.d/init.d/functions"| grep -E -o "[^/]+$"
functions
  扩展:取出其路径名
  [root@localhost~]# echo "/etc/rc.d/init.d/functions" | grep -E -o "^/.*/"
/etc/rc.d/init.d/
3、找出ifconfig命令结果中的1-255之间数字;
  [root@localhost ~]# ifconfig
  eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  inet 192.168.2.108  netmask255.255.255.0  broadcast 192.168.2.255
  inet6 fe80::20c:29ff:fe0d:4a8b prefixlen 64  scopeid0x20<link>
  ether 00:0c:29:0d:4a:8b txqueuelen 1000  (Ethernet)
  RX packets 419  bytes 41325 (40.3KiB)
  RX errors 0  dropped 0  overruns 0 frame 0
  TX packets 337  bytes 46637 (45.5KiB)
  TX errors 0  dropped 0 overruns0  carrier 0  collisions 0
  lo:flags=73<UP,LOOPBACK,RUNNING>  mtu65536
  inet 127.0.0.1  netmask 255.0.0.0
  inet6 ::1  prefixlen 128  scopeid 0x10<host>
  loop  txqueuelen 0  (Local Loopback)
  RX packets 4  bytes 340 (340.0 B)
  RX errors 0  dropped 0  overruns 0 frame 0
  TX packets 4  bytes 340 (340.0 B)
  TX errors 0  dropped 0 overruns0  carrier 0  collisions 0
  virbr0:flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  inet 192.168.122.1  netmask255.255.255.0  broadcast 192.168.122.255
  ether 52:54:00:47:81:6c txqueuelen 0  (Ethernet)
  RX packets 0  bytes 0 (0.0 B)
  RX errors 0  dropped 0  overruns 0 frame 0
  TX packets 0  bytes 0 (0.0 B)
  TX errors 0  dropped 0 overruns0  carrier 0  collisions 0
  [root@localhost ~]#ifconfig | grep -E -o "\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>"
192
168
2
108
255
255
255
0
192
168
2
255
64
29
38
5
0
0
0
0
40
8
0
0
0
0
0
73
127
0
0
1
255
0
0
0
1
128
0
4
0
0
0
0
0
4
0
0
0
0
0
0
192
168
122
1
255
255
255
0
192
168
122
255
52
54
47
81
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4、查找当前系统上没有属主或属组的文件;
  [root@localhost~]# find / -nouser -o -nogroup
/home/mandriva
/home/mandriva/.bash_logout
/home/mandriva/.bash_profile
/home/mandriva/.bashrc
/home/mandriva/.mozilla
/home/mandriva/.mozilla/extensions
/home/mandriva/.mozilla/plugins
find: ‘/proc/3244/task/3244/fd/6’: 没有那个文件或目录
find:‘/proc/3244/task/3244/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/3244/fd/6’: 没有那个文件或目录
find:‘/proc/3244/fdinfo/6’: 没有那个文件或目录
/var/spool/mail/mandriva
[root@localhost ~]#
进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
  [root@localhost ~]# find / \( -nouser -o-nogroup \) -a -atime -3
  /home/mandriva
  /home/mandriva/.mozilla
  /home/mandriva/.mozilla/extensions
  /home/mandriva/.mozilla/plugins
  find: ‘/proc/3254/task/3254/fd/6’: 没有那个文件或目录
  find: ‘/proc/3254/task/3254/fdinfo/6’: 没有那个文件或目录
  find: ‘/proc/3254/fd/6’: 没有那个文件或目录
  find: ‘/proc/3254/fdinfo/6’: 没有那个文件或目录
5、查找/etc目录下大于1M,且类型为普通文件的所有文件;
  [root@localhost ~]# find /etc -size +1M -a-type f -ls
  4239312 6852 -r--r--r--   1 root    root      7014922 12月 11 00:24/etc/udev/hwdb.bin
  202385046 3772 -rw-r--r--   1 root    root      3858924 11月 21  2015 /etc/selinux/targeted/policy/policy.29
  4083229 1336 -rw-r--r--   1 root    root      1367395 3月  6  2015/etc/brltty/zh-tw.ctb
  [root@localhost ~]#
6、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
  [root@localhost ~]# find /etc/init.d/ -perm/113 -ls
  201494444   0 drwxr-xr-x   2 root     root           66 12月 10 00:22/etc/init.d/
  201868855   4 -rwxr-xr-x   1 root     root         2989 9月 16  2015 /etc/init.d/netconsole
  201868856   8 -rwxr-xr-x   1 root     root         6630 9月 16  2015 /etc/init.d/network
7、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
  [root@localhost~]# find /etc/ -not \( -user root -o -user hadoop \) -atime -7 -ls
find: 用户名‘hadoop’ 未知
[root@localhost ~]# find/etc/ -not \( -user root -o -user bin \) -atime -7 -ls
134780546    0 drwx------   2 polkitd root           63 12月 10 00:21 /etc/polkit-1/rules.d
136093649    0 drwx--x--x   2 sssd    sssd            6 8月 3 00:58 /etc/sssd
[root@localhost ~]#
8、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;
  [root@localhost~]# ls /etc/rc.d/
init.d  rc0.d  rc1.d  rc2.d  rc3.d  rc4.d  rc5.d  rc6.d  rc.local
[root@localhost ~]#
  [root@localhost~]# cp /etc/rc.d/rc.local /tmp/
[root@localhost ~]# ls /tmp/
mytest2   systemd-private-62113d01174b48f3b9b96b264b53cd52-cups.service-x1z7b8
rc.local  systemd-private-62113d01174b48f3b9b96b264b53cd52-vmtoolsd.service-pkrcv0
[root@localhost ~]# sed -i 's/\(^[[:space:]]\)/#\1/g' /tmp/rc.local
9、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符
  [root@localhost~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
[root@localhost ~]# cp /etc/rc.d/rc.local /tmp/
[root@localhost ~]# ls /tmp/
mytest2   systemd-private-62113d01174b48f3b9b96b264b53cd52-cups.service-x1z7b8
rc.local  systemd-private-62113d01174b48f3b9b96b264b53cd52-vmtoolsd.service-pkrcv0


  [root@localhost~]# sed -i 's/^#[[:space:]]\+//g' /tmp/rc.local
[root@localhost ~]# cat /tmp/rc.local
#!/bin/bash
THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
It is highly advisable to create own systemd services or udev rules
to run scripts during boot instead of using this file.
#
In contrast to previous versions due to parallel execution during boot
this script will NOT be run after all other services.
#
Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
that this script will be executed during boot.

touch /var/lock/subsys/local
[root@localhost ~]#

10、将/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改为1;
  [root@localhost~]# sed 's/enabled=0/enabled=1/g;s/gpgcheck=1/gpgcheck=2/g;'/etc/yum.repos.d/CentOS-Media.rep

11、每周2,4,6备份/var/log/messages文件至/backup/messages_logs/目录中,保存的文件名形如messages-20161202
  [root@localhost~]# crontab -e
  00 00 * *2,4,6 cp -r /var/log/messages /backup/messages_logs/messages-$(date +/%Y/%m/%d)
12、每天每两小时取当前系统/proc/meminfo文件中的所有以S开头的信息至/stats/memory.txt文件中
  [root@localhost~]# crontab -e
  00 */2 * * *cat /proc/meminfo |grep "^S" >> /stats/memory.txt
13、写一个脚本创建10用户user10-user19;密码同用户名;
  [root@localhost~]# vi test02
  #!/bin/sh
  for i in {10..19};do
  id user$i &>/dev/dull
  if [ $? -eq 0 ];then
  echo "user$i exits"
  else
  useradd user$i
  echo "user$i"| passwd --stdin user$i
  echo "user$i added"
  fi
  done
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-461692-1-1.html 上篇帖子: linux samba实验 下篇帖子: linux 本地路由用法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表