当前位置:首页 » 网页前端 » 一起来写一个shell脚本吧
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

一起来写一个shell脚本吧

发布时间: 2022-02-15 00:13:07

㈠ SHELL写一个脚本

如果删除/xxx/xxxxxx/xxx/下 3天以前的 所有内容:1find /xxx/xxxxx/xxx/* -mtime +3 -exec rm -rf {} \;如果删除/xxx/xxxxxx/xxx/下 3天以前的 所有文件(不包含目录):1find /xxx/xxxxx/xxx/* -type f -mtime +3 -exec rm -rf {} \;如果不删除MSS目录 只删除MSS内的所有 3天以前的 文件:1find /xxx/xxxxx/xxx/MSS[0-9]*/* -type f -mtime +3 -exec rm -rf {} \;如果不删除MSS目录 但MSS下所有 3天以前的 目录及文件全删除:1find /xxx/xxxxx/xxx/MSS[0-9]*/* -mtime +3 -exec rm -rf {} \;

㈡ 如何写一个shell脚本

简单的说,你把你在终端输入的命令放在一个文件里,这个文件就成了shell脚本
比如你编辑一个文件叫 helloworld.sh
内容是
echo "Hello world!"

你把helloword.sh变成可执行的,就是在终端输入
chmod +x helloworld.sh
然后运行
./helloworld.sh

你就成功滴写好了一个shell脚本

㈢ 写一个Shell脚本

此问题其实可以用find命令解决
find dir -t f -empty |xargs rm -f,这样便达到要求了。若想自已用shell实现,我这里有一个,仅做参考。(主要缺点在于,用了递归,没有测试最大能够处理到多少级子目录)
#!/bin/bash -
#by volate
set -u

Pro=$0
Dir=$1

#此函数标明此程序的用法,或者因错误退出的标志及退出码
usage(){
local pro=$1
local ErrStr=$2
local ExitDig=$3
echo "Usage: $pro {Dir}"
echo "Error: $ErrStr"
exit $ExitDig
}

#此函数找出目标目录下的所有文件,并递归到子目录
findFile(){
local dir=$1
cd $dir || usage $Pro "Can't chdir $dir" 2
for f in * ;do
#递归到子目录
test -d $f && findFile $f
#若是文件,则交给下个函数处理
test -f $f && delEmptyFile $f
done
}

#此函数删除大小为0的文件
delEmptyFile(){
local file=$1
#得到文件大小
local fileSize=`ls -l $file | awk '{print $5}'`
#判断大小是否为0
if [ "X$fileSize" = "X0" ]; then
echo "`pwd`/$file is empty, delete..."
rm -f $file || usage $Pro "can't delete $file" 3
fi
}

Pro=$0
if [ $# != 1 ];then
usage $Pro "argv error" 1
fi

Dir=$1
workDir=`pwd`
findFile $Dir
cd $workDir
exit 0

㈣ 请编写一个shell脚本

条件写得倒是很详细的,但发现用脚本不一定要死要求,有时灵活一点更有效率。
如果觉得还不赖,就拿去用吧。
#!/bin/bash

echo "Please Enter a IP of C class"
read ip
i=1
while [[ True ]]
do
if [[ $i -gt 255 ]]; then
echo $i
exit 0
fi
echo "$ip.$i"
ping -c1 -w1 $ip.$i &>/dev/null && echo "$ip.$i">>goodhost || echo "$ip.$i">>badhost
i=`expr $i + 1`
done

㈤ 帮忙写一个linux shell脚本

简单写下,大概就是这样子了。要用的话还要自己修改了。。。。。。。

while true

do
md5sum /path/testda.file > testda.file.md5
for ka in disk{b..m} ; do sed "s@\/path\/testda.file@\/mnt$ka\/testda.file@g" testda.file.md5 >> testda.file.2.md5 ; done

dd if=/path/testda.file of=/mnt/disk{b..m}/testda.file
md5sum -c testda.file.2.md5

rm -f /mnt/disk{b..m}/testda.file
rm -f testda.file{.2}.md5

done

㈥ 编写一个简单Shell脚本完成

#!/bin/sh
who >file
more file

----------------------
其实可以同时实现查看who命令结果和重定向到文件,用双向重导向命令tee就行了:
who|tee file

㈦ 编写一个shell脚本

一楼的可以实现咯,如果不想用现成的rev的话,可以自己写一个:

#!/bin/bash

str=$*
let i=${#str}-1
while [[ i -ge 0 ]]; do
echo -n ${str:$i:1}
let i=$i-1
done
echo

㈧ 编写一个shell脚本程序

awk'{print$0,$3+$4+$5}'bjcj.txt|sort-nr-k6|head-5

awk计算总成绩,并放置原数据后面一列并显示,sort是按照总成绩(第六列)从大到小的数值进行排序,head筛选出前五行数据