我需要创建一个bash脚本,它执行以下操作:
在文件夹位置创建文件
它必须是一个新文件夹
在文件中添加文本数据
查找并替换文件中的句子
将权限更改为只对除所有者以外的所有人读取,必须为读取、写入和执行
将文件移动到另一个文件夹位置
将文件的所有权更改为root:root
对于每个步骤,脚本需要在cmd中显示操作
请看我下面的尝试:
#!/bin/sh
#Creates a file in a folder location
#It has to be a new folder
mkdir Alitest /var
#add text data in the file
vim /var/Alitest/action.txt echo "This is a test that I have created. This is to
see if the output is successful I normally do this manually but a script is required"
#find and replace the sentence in the file
replace "This is a test that I have created" "The test has been successful" -- action.txt
#Change permissions to be read only to everyone apart from the owner it has to be read write and exc
chmod 004 -- action.txt
chmod 700 -- action.txt
#move file to another folder location
mv /var/Alitest/action.text /var/log
#Change ownership on file to be root:root
chown root:root这些都在不同的行上。
请就此提出一些建议,以及如何让脚本显示每个任务的进度?
亲切地问候阿里
发布于 2017-07-11 20:21:47
您可以使用'set -v‘或sh script |tee log
https://stackoverflow.com/questions/45033253
复制相似问题