北邮linux大作业2016参考答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.

(1)

date //打印系统当前的日期和时间等信息

结果:2017年 01月 09日星期一 19:09:15 CST

(2)

arch 显示机器的处理器架构(1)

uname -m 显示机器的处理器架构(2)

uname -r 显示正在使用的内核版本

(3) 没测试广播!

DELAY=1200

wall 'The System is going REBOOT for halt in 20 minutes. Please SAVE your work. \r'

for i in $(seq $DELAY | tac);do

echo -en "The System is going REBOOT for halt in \033[31m ${i} \033[37m seconds. Please SAVE your work. \r"

sleep 1

done

/sbin/reboot -h 0

2.

(1)

操作步骤:

(1)终端窗口下执行命令crontab –e,使用vim编辑计划任务;

(2)在vim窗口中,添加如下几项:

(1) 10 2 * * * rm -r /cdf

(2) 0 0 * * 7 cp -f -r /user/backup /tmp/ #由于是备份,采用强制复制模式

3.

#! bin/sh

sign=1

#输入

if

[ "$#" != 2 ]

then

echo "please make sure that you enter 2 arguments, first is the source file, second is the destination directory."

exit 1

fi #if 1 , check the amount of the arguments.

# 3.检查源文件是否存在

if

[ ! -f "$1" ]

then

echo "the source file(the first argument) doesn't exist, please check your arguments" exit 1

fi #if 2 , check if the source file exists.

# 1.检查源文件和目标文件是否是同一个文件

if

[ "$1" = "$2" ]

then

echo "the source file and the destination is the same file!"

exit 1

fi #if 3 , check the amount of the arguments.

# 2.检查目标文件名格式是否正确

if

echo "$2" | grep -q '^[a-zA-Z0-9_/.]\+$'

then

continue

else

echo "your destination is a invalid file name."

exit 1

fi #if 4, check if the destination is a invalid file name

# 4.检查目标文件是否存在,如果目标文件已经存在则询问是否覆盖

if

[ -f "$2" ]

then

while [ $sign -eq 1 ]

do

echo "the destination file has been created, are u sure to overwrite it?(please enter y/n)" read YesOrNo

case "$YesOrNo" in

y)

cp $1 $2

echo "------------------------------------------"

echo "the file has been copied"

sign=0

continue

;;

Y)

cp $1 $2

echo "------------------------------------------"

echo "the file has been copied"

sign=0

continue

;;

n)

sign=0

break

;;

N)

sign=0

break

;;

*)

sign=1

continue

;;

esac

done

exit 1

fi #if 5, make sure if the user wanna overwrite the file that has been created.

cp $1 $2

if [ "$?"=0 ]

then

echo "copy successfully."

else

echo "some error(s) occured."

fi #if 6, to check if there's sth wrong.

4.

ssh 的非交互式登陆

环境说明:

工作服务器 A: IP 地址 10.193.251.191,操作系统 RHEL5.5,已建立用户 root

工作服务器 B: IP 地址 10.193.251.192,操作系统 RHEL5.5,已建立用户 liubo

思路:在服务器 A 生成一对 RSA 密钥,自己保留私钥。将公钥附加到登陆服务器 B 的

相关文档
最新文档