shell-相关面试题

4.企业面试题

批量创建10个系统帐号oldboy01-oldboy10并设置密码(密码为随机8位字符串)。

#/bin/bach
for n in `seq -w 10`
do
 useradd oldboy-$n
 echo '123456' | passwd --stdin oldboy-$n
done
[root@m01 /server/scripts]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
oldboy-01:x:1001:1001::/home/oldboy-01:/bin/bash
oldboy-02:x:1002:1002::/home/oldboy-02:/bin/bash
oldboy-03:x:1003:1003::/home/oldboy-03:/bin/bash
oldboy-04:x:1004:1004::/home/oldboy-04:/bin/bash
oldboy-05:x:1005:1005::/home/oldboy-05:/bin/bash
oldboy-06:x:1006:1006::/home/oldboy-06:/bin/bash
oldboy-07:x:1007:1007::/home/oldboy-07:/bin/bash
oldboy-08:x:1008:1008::/home/oldboy-08:/bin/bash
oldboy-09:x:1009:1009::/home/oldboy-09:/bin/bash
oldboy-10:x:1010:1010::/home/oldboy-10:/bin/bash

5.

2企业面试题
写一个脚本,实现判断10.0.0.0/24网络里,当前在线用户的IP有哪些(方法有很多)

#!/bin/bach

for n in `seq 1 255`
do
  ping -c 1 10.0.0.$n &>/dev/null
  if [ $? -eq 0 ]
  then
      echo -e "10.0.0.$n is up."
  else
      echo -e "10.0.0.$n is down."
 fi
done

你可能感兴趣的:(shell-相关面试题)